You need to sign in to do that
Don't have an account?
Sagar Hinsu 13
Means based on the date it should take the values of Test1 data and Test2 data..
I tried so many methods but it gives me the "APEX CPU Time Limit" error.
Because first I have to loop through the dates.
Convert sObject List to JSON
I know there are so many question which answers this type of questions but my problem is little different.
I have one object called CRMData__c in that I have Name, CRMDefinition__c(master-detail), Number__c, Date__c fields.
So CRMData__c will have many records with Date, Number__C some number, and CRMDefinition id.
I am showing some data example below for better understanding.
I got the record list in one variable List<sObject> result = "My result";
based on this result I want a JSON like below.
{ "Test1": 12, "Test2": 11, "date": "2018-01-01" }, { "Test1": 15, "Test2": 23, "date": "2018-01-02" }, { "Test1": 20, "date": "2018-01-03" }
Means based on the date it should take the values of Test1 data and Test2 data..
I tried so many methods but it gives me the "APEX CPU Time Limit" error.
Because first I have to loop through the dates.
If you need any other format JSON, you can loop through the map and convert it easily
Let me know if it helps you..
Thanks for the reply but this will give me date as a key json.. i want to iterate over the dates which are present in record and based on date it shoud create the json which i have mentioned in the question.
//if no of data attributes are not fixed, then you can iterate over map and create a json string directly instead of wrapper
List<sObject> listOfData = Database.query(SOQLstatement);
JSON.serialize(listOfData);
Upvoted Sachin Kadian 5's answer.
I found this and solved my problem.
string query='SELECT id, name from account';
string Outputget= JSON.serialize(database.query(query));
system.debug(Outputget);
]
https://salesforcetrail.blogspot.com/2020/05/get-salesforce-soql-result-in-json.html