0

enter image description here

enter image description here

Here i am trying to check whether the case field is editable or not and if it is editable i want to show a text box there, is there any way to check it on Visual Force page itself. can anyone please help me out.

VF Page-

 <apex:pageBlockTable value="{!waAccList}" var="eachRecord" id="table123"> 

  <apex:column headerValue="Action">
    <apex:commandLink value="Remove" style="color:red" action="{!removeRowFromAccList}"  rerender="CaseHead" immediate="true" >
         <apex:param value="{!eachRecord.position}" name="rowToRemove" assignTo="{!rowToRemove}"/>
     </apex:commandLink>

  </apex:column>
  <apex:column headerValue="S.No." id="position">
                       <apex:outputText value="{!eachRecord.position}"/> 
   </apex:column>


   <apex:column headerValue="Case Field">
                        <apex:selectList multiselect="false"  size="1" title="select case Field" value="{!eachRecord.CaseFieldSelected}" > 

                <apex:selectOptions value="{!eachRecord.caseFieldOptions}" />
                <apex:actionSupport event="onchange"  reRender="table123" />
            </apex:selectList><p/>

   </apex:column>
   <apex:column headerValue="Condition">
                        <apex:selectList multiselect="false"  size="1" title="select case Field"  > 

                <apex:selectOptions value="{!eachRecord.operatorOptions}" />
            </apex:selectList><p/>
   </apex:column>
    <apex:column headerValue="Case Name" id="demo">
                       <apex:outputText value="{!eachRecord.caseFieldSelected}"/> 
   </apex:column>
    <apex:column headerValue="Value">
                      <apex:inputField value="{!eachRecord.record[eachRecord.caseFieldSelected]}" rendered="{!!eachRecord.isUpdateable}"/> 
                       <apex:inputText value="{!eachRecord.searchstring}" rendered="{!eachRecord.isUpdateable}"/>
   </apex:column>


</apex:pageBlockTable>

Controller--


   public with sharing class ConditionalPageExtension{

        public PageReference SaveMultipleCases() {
        system.debug('controller save method is calling-->');
         ConditionalPageExtensionhelper.save(waAccList);
        return null;
        }


     public List<WrapperpaCaseList> waAccList {get;set;}
     public Integer rowToRemove {get;set;}

     public ConditionalPageExtension(){
      waAccList = new List<WrapperpaCaseList>();
      addNewRowToAccList();
     }
     public void removeRowFromAccList(){
      waAccList = ConditionalPageExtensionhelper.removeRowToCaseList(rowToRemove, waAccList);
      integer i=1;
      for(WrapperpaCaseList caseobj1 :waAccList ){
          caseobj1.position=i;
          i++;
      }

     }

     public void addNewRowToAccList(){
         waAccList = ConditionalPageExtensionhelper.addNewRowToAccList(waAccList);
        }



     public class WrapperpaCaseList{
            public Integer index {get;set;}
            public Case record {get;set;}
            Public list<selectoption>caseFieldOptions{get;set;}
            Public list<selectoption>operatorOptions{get;set;}
            Public String operatorSelected{get;set;}
            Public String caseFieldSelected{get;set;}
            Public Integer position{get;set;}
            Public boolean isUpdateable{get;set;}
            public String searchstring {get;set;}

               public WrapperpaCaseList(){
                  isUpdateable = false;
               }

       } 
    }

ConditionalPageExtensionhelper--

public class ConditionalPageExtensionhelper {

    public static List<ConditionalPageExtension.WrapperpaCaseList> addNewRowToAccList(List<ConditionalPageExtension.WrapperpaCaseList> waAccObjList){
        ConditionalPageExtension.WrapperpaCaseList newRecord = new ConditionalPageExtension.WrapperpaCaseList();
        Case newCaseRecord = new Case();  

       newRecord.record = newCaseRecord;
        newRecord.index = waAccObjList.size();
        newRecord.operatorOptions= new list<selectoption>();
        newRecord.operatorOptions.add(new Selectoption('=','='));
        newRecord.operatorOptions.add(new Selectoption('!=','!='));
        newRecord.caseFieldOptions = new list<selectoption>();
        Map <String, Schema.SObjectField> fieldMap= Case.sObjectType.getDescribe().fields.getMap();
        integer i=1;
        for(Schema.SObjectField sfield : fieldMap.Values()){ 
            if (i==1){
                newRecord.caseFieldSelected =string.valueof(sfield.getDescribe().getname());
                i++;
            }
           newRecord.caseFieldOptions.add(new selectOption(string.valueof(sfield.getDescribe().getname()),string.valueof(sfield.getDescribe().getlabel())));

        }
        newRecord.position = waAccObjList.size()+1;
        waAccObjList.add(newRecord);
        return waAccObjList;
    }


     public static List<ConditionalPageExtension.WrapperpaCaseList> removeRowToCaseList(Integer rowToRemove, List<ConditionalPageExtension.WrapperpaCaseList> waCaseList){
        rowToRemove = rowToRemove-1;
        waCaseList.remove(rowToRemove);
        integer i=1;
       // system.debug('----->'+waCaseList);

        return waCaseList;
    }

    public static void save(List<ConditionalPageExtension.WrapperpaCaseList> waAccList) {
        system.debug('==waAccList==>'+waAccList.size());
        List<Case> CaseRecordsToBeInserted = new List<Case>();
        if(waAccList !=null && !waAccList.isEmpty()){
            for(ConditionalPageExtension.WrapperpaCaseList eachRecord : waAccList ){
      //          Case accTemp = eachRecord.record;
        //        CaseRecordsToBeInserted.add(accTemp);

            }
            system.debug('==CaseRecordsToBeInserted==>'+CaseRecordsToBeInserted.size());
            insert CaseRecordsToBeInserted;
        }
    }
}
  • 1
    Hey Ratan Are You There ?? @sfdcweb – RAT__ Apr 26 '16 at 10:29
1

Use the following syntax in VF page to check if a field is updateable:

"{!$ObjectType.<ObjectName>.fields.<Field Name>.Updateable}"

the above exp will return true if it is updatable and false otherwise.

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.