1

Im trying to hide my Billing_Account__c inputField on my visualforce page, If my custom field Entitas_New__c = 'Pusat' on my custom object Master_Visit_Plan__c.

This is the vf page, as you can see there`s billing account inputfield : enter image description here

My custom object relationship : Master_Visit_Plan__c (Parent) -> Master_Visit_Plan_Branch__c -> Visit_Plan_Header__c -> Visit_Plan__c

The vf page appear if user press New Visit Plan button on Visit_Plan_Header__c page. (user doesnt have to go to visit_plan tab to create new record, but from master visit plan -> create master visit plan -> visit plan header -> create visit plan)

enter image description here

I tried using rendered with IF condition to hide the billing account inputfield. It works. The inputField disappeared. But its totally disappeared, even if Entitas_New__c != 'Pusat'.

enter image description here

this is my vf :

<apex:page controller="Visit_plan_class">
<apex:form id="formid">
    <apex:message />
    <apex:pageBlock >
        <apex:pageMessages id="errors"/>
        <apex:pageblockbuttons >
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="Add" action="{!add}" rerender="formid"/>
            <apex:commandButton value="cancel" action="{!cancel}"/>
            <apex:commandButton value="delete" action="{!deletede}"/>
        </apex:pageblockbuttons>

       <apex:pageblocktable value="{!listvp}" var="var">
           <apex:column headerValue="Cancel">
                <apex:inputCheckbox value="{!var.cek}"/>
            </apex:column>
           <apex:column headerValue="Visit Plan Header"> 
                 <apex:outputfield value="{!var.vp2.Visit_Plan_Header__c}"/>
           </apex:column>
            <apex:column headerValue="Koordinator Visit"> 
                 <apex:inputfield value="{!var.vp2.Named_User__c}"/>
           </apex:column>
           <apex:column headerValue="Description"> 
                <apex:inputfield value="{!var.vp2.Description__c}"/>
           </apex:column>
           <apex:column headerValue="Customer"> 
                <apex:inputfield value="{!var.vp2.Customer_VF__c}"/>
           </apex:column>
           <apex:column headerValue="Billing Account">
               <apex:inputfield value="{!var.vp2.Billing_Account__c}" rendered="{IF(!var.vp2.Visit_Plan_Header__r.Master_Visit_Plan_Branch__r.Master_Visit_Plan__r.Entitas_New__c='Pusat',false,true)}"/>
           </apex:column>
           <apex:column headerValue="Lead"> 
                <apex:inputfield value="{!var.vp2.Lead__c}"/>
           </apex:column>
           <apex:column headerValue="Plan Date"  > 
               <apex:outputPanel rendered="{!if(var.vp2.id=='',true,false)}">
                    <apex:inputfield value="{!var.vp2.Plan_Date__c}"/>
               </apex:outputPanel>
               <apex:outputPanel rendered="{!if(var.vp2.id=='',false,true)}">
                    <apex:outputfield value="{!var.vp2.Plan_Date__c}"/>
               </apex:outputPanel>     
           </apex:column>
           <apex:column headerValue="Reschedule Date" > 
                <apex:inputfield value="{!var.vp2.Reschedule_Date__c}" rendered="{!if(var.vp2.id=='',false,true)}"/>
           </apex:column>



       </apex:pageblocktable>

    </apex:pageBlock>
</apex:form>

and this is the controller :

public class Visit_plan_class {
public List <Visit_Plan__c> vplist {get;set;}
public List <classVP> listvp {get;set;}

public String idsf{get;set;}
public String kondisi{get;set;}
public String PeriodeTxt{get;set;}
public String HeaderTxt{get;set;}
public String KoorPiC{get;set;}

private ApexPages.StandardController std;

public Visit_plan_class(ApexPages.StandardController controller){
    std = controller;
    visit_plan_class2();
}

public Visit_plan_class(){
    visit_plan_class2();
}

public void visit_plan_class2(){
    listvp = new List<classVP>();
    vplist = new List<visit_plan__c>();
    kondisi = 'new';
    idsf = ApexPages.currentPage().getParameters().get('id');

    if(idsf!=null)
    {
        kondisi = 'update';
        vplist = [SELECT id,Lead__c,named_user__c, description__c,customer__c,Customer_VF__c ,billing_account__c, plan_date__c,reschedule_date__c,visit_plan_header__c,Master_Visit_Plan__r.Periode__c,
                  Master_Visit_Plan__r.Entitas_New__c, Visit_Plan_Header__r.Name
                FROM visit_plan__c WHERE Visit_Plan_Header__c =:idsf];

        Visit_Plan_Header__c vph = [SELECT id, Master_Visit_Plan_Branch__r.Master_Visit_Plan__r.Periode__c, Name, Master_Visit_Plan_Branch__r.Koor_PIC_Customer_Visit__c,
                                    Master_Visit_Plan__r.Entitas_New__c FROM Visit_Plan_Header__c WHERE id =: idsf];

        PeriodeTxt = vph.Master_Visit_Plan_Branch__r.Master_Visit_Plan__r.Periode__c;
        HeaderTxt = vph.Name;
        KoorPiC = vph.Master_Visit_Plan_Branch__r.Koor_PIC_Customer_Visit__c;

        if(vplist.size()>0){
            for(visit_plan__c oks:vplist){
                listvp.add(new classvp(false,oks));
            }              
        }
    }
}

public class classVP{
    public Boolean cek{get;set;}
    public visit_plan__c vp2 {get;set;}
    public classVP(Boolean a, Visit_Plan__c b){
        this.cek = a;
        this.vp2 = b;
    }
}


public void add(){
    Visit_plan__c vp2 = new visit_plan__c();

    vp2.Named_User__c = id.valueof(KoorPiC);

    Integer Year = Integer.ValueOf(PeriodeTxt);

    if (HeaderTxt.Contains('Januari')){
        vp2.Plan_Date__c = Date.newInstance(Year, 1, 1);        
    }
    if (HeaderTxt.Contains('Februari')){
        vp2.Plan_Date__c = Date.newInstance(Year, 2, 1);        
    }
    if (HeaderTxt.Contains('Maret')){
        vp2.Plan_Date__c = Date.newInstance(Year, 3, 1);        
    }
    if (HeaderTxt.Contains('April')){
        vp2.Plan_Date__c = Date.newInstance(Year, 4, 1);        
    }
    if (HeaderTxt.Contains('Mei')){
        vp2.Plan_Date__c = Date.newInstance(Year, 5, 1);        
    }
    if (HeaderTxt.Contains('Juni')){
        vp2.Plan_Date__c = Date.newInstance(Year, 6, 1);        
    }
    if (HeaderTxt.Contains('Juli')){
        vp2.Plan_Date__c = Date.newInstance(Year, 7, 1);        
    }
    if (HeaderTxt.Contains('Agustus')){
        vp2.Plan_Date__c = Date.newInstance(Year, 8, 1);        
    }
    if (HeaderTxt.Contains('September')){
        vp2.Plan_Date__c = Date.newInstance(Year, 9, 1);        
    }
    if (HeaderTxt.Contains('Oktober')){
        vp2.Plan_Date__c = Date.newInstance(Year, 10, 1);        
    }
    if (HeaderTxt.Contains('November')){
        vp2.Plan_Date__c = Date.newInstance(Year, 11, 1);        
    }
    if (HeaderTxt.Contains('Desember')){
        vp2.Plan_Date__c = Date.newInstance(Year, 12, 1);        
    } 
    //listvps.add(vp2);  
    //System.debug('Test:' + vp2.id);
    listvp.add(new classvp(false,vp2));

}

public pageReference save(){
    try{
        List<visit_plan__c> listvps = new List<visit_plan__c>();
        for(classvp cvp:listvp){
            if(cvp.cek==false){
                cvp.vp2.visit_plan_header__c = idsf;
                listvps.add(cvp.vp2);    
            }

        }
        upsert listvps;
    }catch(Exception e){
       if (PesanError.Contains('DUPLICATE_VALUE'))
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'Customer / Billing Account sudah pernah dibuat.'));
       else if (!PesanError.Contains('FIELD_CUSTOM_VALIDATION_EXCEPTION'))
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ''+e.getMessage()));

       return null;
    }

    PageReference pr = new PageReference('/'+idsf);
    return pr;


}

Public void deletede()
{
    List <Visit_Plan__c> vp3 = new List<Visit_Plan__c>();
    List <classVP> classvp2 = new List <classVP>();
    for(classVP cvp2:listvp)
    {
        if(cvp2.cek==true){
            if(cvp2.vp2.id!=null) vp3.add(cvp2.vp2);
        }else{
            classvp2.add(cvp2);
        }
    }
    listvp = classvp2;
    try{
        if(vp3.size()>0) delete vp3;
    }catch(exception e){}

}

public PageReference cancel(){
    schema.DescribeSObjectResult r = visit_actual__c.sObjectType.getDescribe();
    String keyPrefix = r.getKeyPrefix();
    String idini = '';
    if(idsf!=null) idini = idsf;
    else idini = keyprefix;
    PageReference  pr = new PageReference('/'+idini);
    pr.setRedirect(true);
    return pr;

}

}

can someone help me or give me reference

  • try to use outputpannel.check that condition using rendered – SFDC FAN Aug 10 '18 at 11:03
0

You may just have to debug a bit more here. Just remove the rendered condition for now and print your Entitas_New__c value before tag apex:inputfield and see the output just like as I shown below- Once you seen the output you will get to know whether you are receiving correct value from apex controller or not-

{!var.vp2.Visit_Plan_Header__r.Master_Visit_Plan_Branch__r.Master_Visit_Plan__r.Entitas_New__c} : apex:inputfield value="{!var.vp2.Billing_Account__c}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.