4

I know about the metadata api but the issue seems to be that its based on the SOAP apis? is there anyway to get the fieldsets from the rest api?

4

SO for me this did not looked possible through standard REST API .So went ahead and built a custom logic as Apex REST which i unit tested and looks ok to me

@RestResource(urlMapping='/sample')
 global class SampleRestWebservice{

global class fieldsetmainwrapper{

  public List<fieldsetwrapper> fsetwrap;
  public string fieldsetname;

}

 public class fieldsetwrapper{

 public string fieldname;
 public string fieldlabel;
 public string fieldtype;
 public string fieldpath;
 public boolean isrequired;
  public boolean isDBrequired;

}

 @HttpGet
 global static List<fieldsetmainwrapper> getstring(){
    Map<String, Schema.FieldSet> FsMap =Schema.SObjectType.Account.fieldSets.getMap();
    List<fieldsetmainwrapper> fwrap=new List<fieldsetmainwrapper>();
    for(string s:FsMap.keyset()){
        fieldsetmainwrapper fmain=new fieldsetmainwrapper();
        fmain.fieldsetname=s;
        List<fieldsetwrapper> fieldwrappers=new  List<fieldsetwrapper>();
        for(Schema.FieldSetMember fieldSetMemberObj:Schema.SObjectType.Account.fieldSets.getMap().get(s).getFields()){
             fieldsetwrapper fwrap1=new fieldsetwrapper();
            // fwrap1.fieldname=fieldSetMemberObj.getName();
             fwrap1.fieldpath=fieldSetMemberObj.getFieldPath(); //api name
             fwrap1.fieldlabel=fieldSetMemberObj.getLabel();
             fwrap1.isrequired=fieldSetMemberObj.getRequired();
             fwrap1.isDBrequired=fieldSetMemberObj.getDbRequired();
             fwrap1.fieldtype=String.valueof(fieldSetMemberObj.getType());   //type - STRING,PICKLIST
             fieldwrappers.add(fwrap1);
        }
        fmain.fsetwrap=fieldwrappers;
        fwrap.add(fmain);
    }
    return fwrap;
 }


}

enter image description here

Please note this is quick and little dirty but can be enhanced to get exact results .

  • Interesting idea. This should work nicely for us. will give it a shot. Thanks for sharing – Keith Mancuso Jun 3 '14 at 19:55

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.