function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohit KapoorMohit Kapoor 

Having problems handling standard fields in a VF page

I have a part of code where we are calling in a list and displaying the values on VF page, The code is

public void orderMod() {
        string str = ApexPages.CurrentPage().getParameters().get('strSerialVal');
        system.debug('----------------------------------> ' + str);
        str = str.replace('_[]=c', '__c');            //parse values
        str = str.replace('&', ',');                 //parse values
        system.debug('----------------------------------> ' + str);
       
        String[] stringLst;
        stringLst = str.split(',');
        system.debug('----------------------------------> ' + stringLst);
        listFieldToShow.clear();
       
        //listFieldToShow.add('Name');
       
        for(string i : stringLst)
        {
            listFieldToShow.add(i);
        }  
        system.debug('----------------------------------> QUERY LIST: ' + listFieldToShow);
       
        setupQuery();
        system.debug('----------------------------------> QUERY String: ' + theQuery);
    }

The problem that I am facing is with standard fields. As standard fields do not have __c, those fields are being left out from the displayed list on the VF page.
Vinit_KumarVinit_Kumar
You should be using contains method of String and use it in if and else contains to differentiatae standard and custom fields,something like below :-

//for custom fields
 if(str.contains('__c')){
  // do you logic
}
// for standard fields
else
{
   //do your logic
}


Mohit KapoorMohit Kapoor
I am passing multiple fields in str. This is a list that is being passed. So there will be always be __c in the field. Though I can put 

if((!str.contains('Name'))||(!str.contains('OwnerId'))){
//logic
}

But that brings me to another question, I am doing a sort and all the fields are having a sequence lets say there are City__c, Address__c, Name,State__c,OwnedID.

What would be logic so that the order is maintained. Until now it was pretty simple, but if I put something like this, then I would need a logic to get the positions of the fields. 

Got any idea. Thanks.
Vinit_KumarVinit_Kumar
Unless you Split your List of String,how will you differentiate Standard and Custom fields.

I see you have 

stringLst = str.split(',');

so the way I suggested you should be applied after splitting the String.

Regarding your next question,once you have identified the Fields you sould add them in another List in the order you want it to be.

Hope this helps !!