1

I am trying to save below class but getting the error at line:

options.add(new SelectOption(String.valueOf(fieldSetMemberObj.getFieldPath())), String.valueOf(fieldSetMemberObj.getLabel()));

I tried to convert this to string but still not working

    public class adssReportBuilder {
    public List<Schema.FieldSetMember> accfieldSetMemberList{get; set;}
    public List<Schema.FieldSetMember> pacfieldSetMemberList{get; set;}
    public List<Schema.FieldSetMember> confieldSetMemberList{get; set;}
    public string[] selectedFields {get; set;} 
    public adssReportBuilder(){
        List<Schema.FieldSetMember> accfieldSetMemberList = readFieldSet('AccFieldSet','Account');
        List<Schema.FieldSetMember> pacfieldSetMemberList = readFieldSet('PAFieldSet','ADSS_Platform_Account__c');
        List<Schema.FieldSetMember> confieldSetMemberList = readFieldSet('ConFieldSet','Contact');
        selectedFields = new String[]{};
    }

    public List<SelectOption> getAccountFields() {
        List<SelectOption> options = new List<SelectOption>(); 
        for(Schema.FieldSetMember fieldSetMemberObj : accfieldSetMemberList){
            options.add(new SelectOption(String.valueOf(fieldSetMemberObj.getFieldPath())), String.valueOf(fieldSetMemberObj.getLabel())); 
        }     
        return options;         
    }

    public static List<Schema.FieldSetMember> readFieldSet(String fieldSetName, String ObjectName){
        Map<String, Schema.SObjectType> GlobalDescribeMap = Schema.getGlobalDescribe(); 
        Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(ObjectName);
        Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe();
        //system.debug('====>' + DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName));
        Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName);
        //List<Schema.FieldSetMember> fieldSetMemberList =  fieldSetObj.getFields();
        //system.debug('fieldSetMemberList ====>' + fieldSetMemberList);  
        return fieldSetObj.getFields(); 
    }  
}

1 Answer 1

3

Your parentheses are not quite right. You have one extra after your fieldPath.

options.add(new SelectOption(
    String.valueOf(fieldSetMemberObj.getFieldPath()),
    String.valueOf(fieldSetMemberObj.getLabel())
));

Of note, those methods on FieldSetMember already return string, so you can make it less confusing by removing your calls to String.valueOf:

options.add(new SelectOption(
    fieldSetMemberObj.getFieldPath(),
    fieldSetMemberObj.getLabel()
));
2
  • Ahh, it was such a silly mistake. Thank you @adrian Commented May 25, 2016 at 16:01
  • 1
    Done, SFSE does not allow to accept immediately !! Commented May 25, 2016 at 16:10

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.