Skip to content
Salesforce Factory
Salesforce Factory

Salesforce Factory

A Complete Blog on Salesforce and Beyond

  • Home
  • Authors
  • Contact

Tag: JSON Structure for Salesforce SObjects

Posted on August 30, 2019August 30, 2019

JSON Structure for Salesforce SObjects

  • tweet 
  • share 
  • share 

The requirement was to get the JSON Structure of an Account object for a third-party tool to Map the fields and Load the object fields.

The Structure needed was only to have the Object name and all the Field Names from the object like Below:

I simplified the way to extract the actual JSON Structure for an Object and get all the fields. Below I have given the code for getting the JSON structure for both API names of the fields and Label names.

Execute below in Execute Anonymous Window for JSON structure with API names of the fields

map<string, map<string,string> > fieldList = new map<string, map<string,string> >();

 map<string,SObjectField> fList = schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap();
 MAP<String,String> fieldandtype = new MAP<String,String>();  
 for(string str: fList.keySet()){
          fieldandtype.put(str,'');
   }
fieldList.put('Account',fieldandtype);
system.debug('-->'+Json.serialize(fieldList));

Execute below in Execute Anonymous Window for JSON structure with Label names of the fields

map<string, map<string,string> > fieldList = new map<string, map<string,string> >();

 map<string,SObjectField> fList = schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap();
 MAP<String,String> fieldandtype = new MAP<String,String>();  
 for(string str: fList.keySet()){
          fieldandtype.put(fList.get(str).getDescribe().getLabel(),'');
   }
fieldList.put('Account',fieldandtype);
system.debug('-->'+Json.serialize(fieldList));

After executing, Open Raw Log and Capture the Unformatted structure of the object and use the Online JSON formatter to get the formatted version like below.

This will help us to save time in extracting the JSON Structure of SObject.

–Ranjith T [08/30/2019]

  • tweet 
  • share 
  • share 

Enter Keywords

Categories

  • Admin Posts (7)
  • Developer Posts (20)
  • Discussions (1)
  • Lightning Communities (1)
  • Salesforce CMS (1)

Archives

  • June 2021 (1)
  • March 2021 (2)
  • January 2021 (1)
  • September 2020 (1)
  • August 2020 (1)
  • June 2020 (3)
  • September 2019 (1)
  • August 2019 (1)
  • July 2019 (1)
  • March 2019 (4)
  • February 2019 (1)
  • January 2019 (2)
  • November 2018 (2)
  • October 2018 (9)

Recent Posts

  • Salesforce Summer’21 release Highlights / Development / Administration June 7, 2021
  • Deleting Apex Classes / Apex Triggers from Production using Workbench March 2, 2021
  • Salesforce CMS March 2, 2021
  • Salesforce Spring ’21 Highlights / KeyPoints / Non-Lightning January 12, 2021
  • Salesforce Winter ’21 release notes – Highlights September 10, 2020

Advertisement

Advertisement

About This Site

Saleforce Factory

A Complete Blog on Salesforce and Beyond

Site Statistics

  • Visitors today : 0
  • Total visitors : 71,324
Proudly powered by WordPress