I want to build a custom sync framework and combine serval object's data to a Json string. For example
List<Account> accounts = [select Id, Name, ... from Account where ...];
The sOBject is dynamic, it can be Account, Contact or CustomObject__c and the fields is also dynamic. the field between select and from clause is flexible. That means I don't know there will be how many fields. I want to convert the select result to this format:
{
"records": [
{
"values": [
"00190000014IoCoAAK | 00081 | Super Mart | ...",
"00190000014EoCAABK | 00082 | Test Mart | ...",
],
"objName": "Account",
"fields": "Id,AccountNumber,Name, ..."
},
{
"values": [
"0039000001JDBt7AAH | 00190000014IoCoAAK | Ues1 | ..."
],
"objName": "Contact",
"fields": "Id,AccountId,Name, ..."
}
]
}
How can I build a Apex calss to handle this Json?