How to create JSON String using Apex in Salesforce?

How to create JSON String using Apex in Salesforce?

JSON.serialize() method can be used to create JSON String using Apex in Salesforce.

Check the following code for reference

Sample Code:

Account objAccount = [
    SELECT Id, Name, Phone, Website, Rating, Industry
    FROM Account
    WHERE Name = 'InfallibleTechie'
    LIMIT 1
];
System.debug(
    JSON.serialize(
        objAccount
    )
);

Leave a Reply