You need to sign in to do that
Don't have an account?
Sam Ward
remove fields from JSON output.
Hi,
I'm wanting to remove currency, ID, and recordtypeid from my JSON file but I can't seem to find a way to remove them from the JSON file, Can someone advise where / What I need to be looking at to. Please see the code below.
My currnet output:
How can I remove them.
Also any general code improvments would be welcomed.
Thanks
I'm wanting to remove currency, ID, and recordtypeid from my JSON file but I can't seem to find a way to remove them from the JSON file, Can someone advise where / What I need to be looking at to. Please see the code below.
public class JsonGenDispositionData { public String jsonString {set;get;} public static void gatherDispositionData(){ List<stage_tracker__c> dispositionDataToSend = [SELECT Distribution_id__c,contact_status__c FROM Stage_Tracker__c WHERE Distribution_id__c != null LIMIT 3]; List<Stage_tracker__c> payload = new list <Stage_Tracker__c>(); // system.debug('Stage Trackers' + dispositionDataToSend); If(dispositionDataToSend.isempty()==false){ JSONGenerator gen = JSON.createGenerator(true); for(Stage_Tracker__c ST : dispositionDataToSend){ gen.writeStartArray(); gen.writeStartObject(); gen.writeStringField('DISTRIBUTION_ID', ST.Distribution_Id__c); gen.writeBooleanField('CONTACT_STATUS', ST.contact_status__c); gen.writeEndObject(); gen.writeEndArray(); payload.add(ST); } } string jsonString = JSON.serialize(payload); system.debug(jsonString); } }
My currnet output:
[{"attributes":{"type":"Stage_Tracker__c","url":"/services/data/v53.0/sobjects/Stage_Tracker__c/a5i3z000000UKNZAA4"}, "Distribution_Id__c":"8056fec2-b009-2cde-2d98-5f9ad4", "contact_status__c":true, "Id":"a5i3z000000UKNZAA4", "RecordTypeId":"0123z000000gHwCAAU", "CurrencyIsoCode":"GBP"}]I dont need the last 3 lines, (Id / RecordTypeId / CurrencyIsoCode)
How can I remove them.
Also any general code improvments would be welcomed.
Thanks
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
In my case i want to fetch list of record, but it's is fetching only one record.
receving below error "Invalid conversion from runtime type List<ANY> to Map<String,ANY>".
Could you please help me how to resolve it.
Thanks in Advance..