Rendered doesn't work - salesforce

If I try to rendered the code below it doesn't work.
If I show me the size of the list I will get the value 1, but nothing is happen.
Where is the mistake?
I tried it also with != NULL .isempty etc., the same problem.
<apex:pageblock title="Unternehmen Detail" id="pbAccDL" rendered="{!If(AccDList2.size > 0,true,false)}>
<apex:pageblocktable value="{!AccDList2}" var="AccD" rendered="{!IF(AccDList2.size != 0, true, false)">
<apex:column style="font-size:16pt; font-weight: bold" headerValue="" value="{!AccD.Name}"/>
</apex:pageblocktable>
<apex:pageblocktable value="{!AccDList2}" var="AccD" columnswidth="50%, 25%, 25%">
<apex:column value="{!AccD.BillingStreet}"/>
<apex:column value="{!AccD.BillingPostalCode}"/>
<apex:column value="{!AccD.BillingCity}"/>
</apex:pageblocktable>
Public List <Account> getAccDList2() {
List <Account> AccD = [SELECT Id, Name, RecordTypeId, Status__c, Kunde_seit__c, Billingstreet, BillingPostalCode, BillingCity FROM Account WHERE Id = :SelectedAccountId];
RETURN AccD;
}
Public pageReference getAccDList() {
getAccDList2();
//RETURN NULL;
RETURN ApexPages.CurrentPage();
}
I don't understand the problem, because I use the same function for an other pageblock and works fine.
<apex:pageblock title="Account" id="pbAcc" rendered="{!IF(AccList2.size != NULL,true,false)}">
<apex:pageblockButtons location="top">
<apex:commandButton value="page 1" rerender="pbAcc" action="{!FirstPage}" disabled="{!prev}"/>
<apex:commandButton value="prev page" rerender="pbAcc" action="{!previous}" disabled="{!prev}"/>
<apex:commandButton value="next page" rerender="pbAcc" action="{!next}" disabled="{!nxt}"/>
<apex:commandButton value="last page" rerender="pbAcc" action="{!LastPage}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<apex:pageblocktable value="{!AccList2}" var="Acc" columnswidth="5%, 70%, 25%">
<apex:column headervalue="LINK">
<apex:outputLink target="_blank" value="/{!Acc.Id}">Details</apex:outputLink>
</apex:column>
<apex:column headervalue="Account">
<apex:outputField value="{!Acc.Name}" />
<apex:actionSupport event="onclick" action="{!getOppList}" rerender="pbOpp, pbAccDL, pbAccDR, pbOppD">
<apex:param assignTo="{!SelectedAccountId}" value="{!Acc.Id}" name="SelectedAccountId"/>
</apex:actionSupport>
</apex:column>
<apex:column headervalue="City">
<apex:outputField value="{!Acc.BillingCity}"/>
</apex:column>
</apex:pageblocktable>
Could someone help me please.
Thanks,
peX

Note that if the outer container (apex:pageBlock in your case) wasn't rendered at page load time you wouldn't be able to rerender inner elements later. To make sure this is not the problem remove rendered attribute from outer apex:pageblock. One more thing to note in your second example you are writing AccList2.size != NULL which is never the case (if AccList2 is a list) you should check with AccList2.size > 0

Related

Opening a VF Page in new tab/window

I am new to Salesforce Lightning and trying to convert a classic button that opens a VF page in a new pop up window (Detail page button) into a Lightning component doing the same. Below is what I tried, created a New Action in Lightning and linked it to tho the below lightning component
selectCampignContainer.cmp (iframe to open the VF page in a new window)
<aura:component implements="force:lightningQuickAction" access="global">
<aura:attribute name='vfpName' type='String'/>
<iframe src="https://abc.lightning.force.com/apex/ +v.vfpName" width="100%" height="500px;" frameBorder="0"/>
</aura:component>
selectCampignContainerController.cmp
({
handleClick : function (cmp, event, helper) {
var evt = $A.get("e.force:navigateToComponent");
evt.setParams({
componentDef : "c:selectCampignContainer",
componentAttributes: {
vfpName : 'Campaign_Selection_Page'
}
});
evt.fire();
}
});
And the VF page is like
<apex:page standardController="Opportunity" extensions="Campaign_Selection_Page_Ext" id="page" showHeader="false" sidebar="false" lightningStylesheets="true" >
<apex:form id="form">
<apex:pageBlock title="Campaign Attribution" id="pageBlock">
<apex:pageblockSection >
<apex:outputField value="{!currentRecord.CampaignId}" label="Primary Campaign"/>
</apex:pageblockSection>
<apex:pageBlockSection title="Search Criteria" collapsible="false">
<apex:inputText value="{!campaignRecord.Name}"/>
<apex:inputField value="{!campaignRecord.StartDate}"/>
<!--<apex:inputField value="{!campaignRecord.Type}"/>-->
<apex:selectList value="{!campaignRecord.Type}" multiselect="false" size="1">
<apex:selectOptions value="{!campaignType}" ></apex:selectOptions>
</apex:selectList>
<apex:inputField value="{!campaignRecord.EndDate}"/>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1">
<apex:outputPanel style="float:right;">
<apex:commandButton value="Search" action="{!search}" rerender="form"/> <apex:commandButton value="Assign Campaign" action="{!assign}" rerender="form"/>
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection title="Search Results"></apex:pageBlockSection>
<apex:pagemessages ></apex:pagemessages>
<apex:pageBlockTable value="{!campaignRecords}" var="rec" id="pbTable">
<apex:column id="pbColumn" >
<apex:inputCheckbox value="{!rec.bol}">
<apex:actionSupport event="onchange" action="{!selectUnselect}" reRender="pbTable">
<apex:param value="{!rec.Campaig.Id}" assignTo="{!selectedCampaign}" name="recId"/>
</apex:actionSupport>
</apex:inputCheckbox>
</apex:column>
<apex:column value="{!rec.Campaig.Name}"/>
<apex:column value="{!rec.Campaig.Campaign_Short_Name__c }"/>
<apex:column value="{!rec.Campaig.Type}"/>
<apex:column value="{!rec.Campaig.StartDate}"/>
<apex:column value="{!rec.Campaig.EndDate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
But when I clicked the button in lightning I get error like
This VF page works perfectly in the Classic and I have just included lightningStylesheets="true". Can anyone please let me know what am I missing here

Salesforce show all cases based on criteria in visualforce

All,
I am attempting to show all cases that meet certain criteria in salesforce using visual force page, then I would like to use that data in a gantt chart. I do know much about coding, but trying based on user manuals. This visualforce page comes back without any case information.
<apex:page standardController="Case" >
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:PageBlockTable value="{!Case}" var="c">
<apex:column value="{!c.Account}"/>
<apex:column value="{!c.Number}"/>
<apex:column value="{!c.Owner}"/>
<apex:column headerValue="Install Date">
<apex:inputField value="{!a.Planned_Install_Date__c}"/>
</apex:column>
</apex:PageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
You need an apex controller class to get data from Salesforce to the visual force page. Something like this:
Visual Page:
<apex:page standardController="Case" controller="MyCaseController">
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:PageBlockTable value="{!Cases}" var="c">
<apex:column value="{!c.Accountid}"/>
<apex:column value="{!c.CaseNumber}"/>
<apex:column value="{!c.OwnerId }"/>
</apex:PageBlockTable>
</apex:pageBlock>
</apex:form>
Controller:
public class MyCaseController {
public list<Case> cases {get;set;}
public MyCaseController(){
cases = [select id, accountid, CaseNumber, OwnerId from case];
}
}
You should be able to accommodate the code to your needs.

Salesforce Updating Checkbox value on change event

Here hidden_field__c is a checkbox.
When in the VFP if user changes the checkbox to true in the database it still shows as false and vice-versa
Can someone please point out what's missing in my code.?
This is my code.
-----------controller --------------
public class dataTableCon {
List<Account> accounts;
public List<Account> getAccounts() {
if(accounts == null) accounts = [select name, owner.name,hidden_field__c from account limit 10];
return accounts;
}
}
---------VFP-------------
<apex:page controller="dataTableCon" id="page">
<apex:form >
<apex:pageBlock id="theBlock">
<apex:dataTable value="{!accounts}" var="account" id="theTable" rowClasses="odd,even" styleClass="tableClass">
<apex:column >
<apex:facet name="header">Private</apex:facet>
<apex:inputCheckbox value="{!account.hidden_field__c}" >
<apex:actionSupport event="onchange" rerender="theBlock"/>
</apex:inputCheckbox>
</apex:column>
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputText value="{!account.name}" >
</apex:column>
<apex:column >
<apex:facet name="header">Owner</apex:facet>
<apex:outputText value="{!account.owner.name}" >
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>
You need to have some mechanism that actually saves the changes. Try adding an <apex:commandButton> inside your <apex:form>, and then have that button call an action that saves.
Apex:
public PageReference save()
{
update accounts;
}
Visualforce:
<apex:commandButton value="Save" action="{!save}"/>

On Salesforce.com can you filter an apex:pageBlockTable by RecordType?

I have the following visualforce page and need to filter either the related lists or the pageblocktables by the case.recortype or case.recordtype.id field. Can anyone guide me to finding out how to do this? Thanks
<apex:page standardController="Account" >
<apex:pageblock title="Cases" >
<apex:pageblockSection >
<apex:relatedList title="Support Cases" list="Cases"/>
</apex:pageblockSection>
<apex:pageblockSection >
<apex:relatedList title="Training Cases" list="Cases"/>
</apex:pageblockSection>
</apex:pageblock>
<apex:pageBlock title="Support Cases" >
<apex:pageBlockTable value="{!Account.Cases}" var="c">
<apex:column headervalue="Case"><apex:outputLink value="/{!c.id}">{!c.CaseNumber}</apex:outputLink></apex:column>
<apex:column value="{!c.Contact.Name}"/>
<apex:column value="{!c.Subject}"/>
<apex:column value="{!c.Priority}"/>
<apex:column value="{!c.CreatedDate}"/>
<apex:column value="{!c.status}"/>
<apex:column value="{!c.createdbyId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Training Cases" >
<apex:pageBlockTable value="{!Account.Cases}" var="c">
<apex:column headervalue="Case"><apex:outputLink value="/{!c.id}">{!c.CaseNumber}</apex:outputLink></apex:column>
<apex:column value="{!c.Contact.Name}"/>
<apex:column value="{!c.Subject}"/>
<apex:column value="{!c.Priority}"/>
<apex:column value="{!c.CreatedDate}"/>
<apex:column value="{!c.status}"/>
<apex:column value="{!c.createdbyId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Update: This is What I actually ended up doing:
Page:
<apex:page standardController="account" extensions="SupportCasefilter,TrainingCasefilter">
<apex:form >
<apex:pageBlock title="Support Cases">
<apex:pageBlockTable value="{!SupportCases}" var="s">
<apex:column headervalue="Case"><apex:outputLink value="/{!s.id}">{!s.CaseNumber}</apex:outputLink></apex:column>
<apex:column value="{!s.Contact.Name}"/>
<apex:column value="{!s.Subject}"/>
<apex:column value="{!s.Priority}"/>
<apex:column value="{!s.CreatedDate}"/>
<apex:column value="{!s.status}"/>
<apex:column value="{!s.createdbyId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Training Cases">
<apex:pageBlockTable value="{!TrainingCases}" var="t">
<apex:column headervalue="Case"><apex:outputLink value="/{!t.id}">{!t.CaseNumber}</apex:outputLink></apex:column>
<apex:column value="{!t.Contact.Name}"/>
<apex:column value="{!t.Subject}"/>
<apex:column value="{!t.Priority}"/>
<apex:column value="{!t.CreatedDate}"/>
<apex:column value="{!t.status}"/>
<apex:column value="{!t.createdbyId}"/>
<apex:column value="{!t.recordtype.id}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
controller1:
public with sharing class SupportCasefilter {
public id accRecId;
public SupportCasefilter(ApexPages.StandardController controller) {
accRecId = [select id from account where id = :ApexPages.currentPage().getParameters().get('id')].id;
}
List<case> supportCases;
public List<case> getSupportCases() {
if(accRecId != null) {
supportCases= [SELECT Id, Contact.name, recordtype.id, casenumber, subject, priority, createddate, status, createdbyid
FROM Case
WHERE Record_Type__c='Support' AND account.id=:accRecId];
}
return supportCases;
}
}
controller2:
public with sharing class TrainingCasefilter {
public id accRecId;
public TrainingCasefilter(ApexPages.StandardController controller) {
accRecId = [select id from account where id = :ApexPages.currentPage().getParameters().get('id')].id;
}
List<case> trainingCases;
public List<case> getTrainingCases() {
if(accRecId != null) {
trainingCases= [SELECT Id, Contact.name, recordtype.id, casenumber, subject, priority, createddate, status, createdbyid
FROM Case
WHERE Record_Type__c='Training' AND account.id=:accRecId];
}
return trainingCases;
}
}
Here's what I have done in the past:
1 - Create a List<RecordType> validRecordTypes that contains valid RecordTypeIds in the Controller
2 - Filter your objects Account.Cases using the the list validRecordTypes in the Controller.
3 - When you try to access Account.Cases in the VisualForce page, the objects should be post-filtered objects
I'd recommend applying the record type filter within the controller itself using a SOQL query before passing the results into the pageBlockTable.

Error : Unknown constructor

I have created a custom object "Assure__c" and a custom apex class "insEnfant" like this :
<apex:page standardController="Assure__c" extensions="insEnfant" standardStylesheets="true">
<apex:sectionHeader title="Ajouter un assuré"
subtitle="{!$User.FirstName}" help="/help/doc/user_ed.jsp?loc=help"></apex:sectionHeader>
<apex:form >
<apex:pageBlock title="Nouveau assuré" id="thePageBlock" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Enregistrer"></apex:commandButton>
<apex:commandButton action="{!cancel}" value=" Annuler "></apex:commandButton>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Liste des enfants" columns="1"
rendered="{!IF(Assure__c.Nombre_enfants__c > 0, true, false)}">
<apex:pageBlockTable value="{!accts}" var="a" id="table">
<apex:facet name="footer">
<apex:commandLink value="Ajouter" action="{!addRow}" rerender="table,error"/>
</apex:facet>
<apex:column headerValue="Nom">
<apex:inputHidden value="{!Assure__c.Name}" id="theHiddenInput"/>
</apex:column>
<apex:column headerValue="Nom">
<apex:inputField value="{!a.Name}"/>
</apex:column>
<apex:column headerValue="Prénom">
<apex:inputField value="{!a.Prenom__c}"/>
</apex:column>
<apex:column headerValue="Né le">
<apex:inputField value="{!a.Date_de_naissance__c}"/>
</apex:column>
<apex:column headerValue="Lieu de naissance">
<apex:inputField value="{!a.Lieu_de_naissance__c}"/>
</apex:column>
<apex:column headerValue="Situation">
<apex:inputField value="{!a.Situation__c }"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
public class insEnfant{
public List<Enfants__c> accts {get; set;}
public insEnfant(){
accts = new List<Enfants__c>();
accts.add(new Enfants__c());
}
public void addrow(){
accts.add(new Enfants__c());
}
public PageReference save(){
insert accts;
PageReference home = new PageReference('/home/home.jsp');
home.setRedirect(true);
return home;
}
}
But when I tried to save it I obtain this error:
Error: Unknown constructor 'insEnfant.insEnfant(ApexPages.StandardController controller)'
Create Apex method 'insEnfant.insEnfant(ApexPages.StandardController controller)'
As I am new to salesforce.com, can anyone please give me the code for this??
Take a look at http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm which explains that a controller extension needs to have a constructor that takes a StandardController as argument. (You've provided a constructor that takes no arguments.) There's some sample code on that page that you may find helpful.

Resources