+ Start a Discussion
Meena25Meena25 

System.JSONException

System.JSONException: Apex Type unsupported in JSON: Schema.SObjectType (through reference chain: common.api.soap.wsdl.FieldSet["sobjectType"])

Schema.FieldSet fs1 = Schema.SObjectType.Lead.fieldSets.getMap().get('CreateLeadElmoService');
system.debug('fs1 -->' + fs1);
string body = JSON.serialize(fs1);

I am unable to serialize my fieldset. please suggest solutions.
Maharajan CMaharajan C
Hi Meena,

If you just want the Fields from FieldSet then you can use the below code:

Schema.FieldSet fs1 = Schema.SObjectType.Lead.fieldSets.getMap().get('CreateLeadElmoService');
system.debug('fs1 -->' + fs1);

List<String> fieldschema = new List<String>();

for(Schema.FieldSetMember sfield : fs1.getFields() ) {
   fieldschema.add(''+sfield);
}
string body = JSON.serialize(fieldschema);

system.debug(' ==> ' + body);

Thanks,
Maharajan.C
Meena25Meena25

system.debug('fs1 -->' + fs1); is getting truncated and am unable to see lead id etc.. how can i limit this fieldset to 1 like in a query?

i gett status code 411 --> length required as of now.