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
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.