You need to sign in to do that
Don't have an account?
Raksha Narayan
Separate the values received from list<sobject> in apex
I have a list<sobject> called SobjList storing the result as follows:
SobjList=(Case:{Id=5002f0000043zxWAAQ, Subject=New case, CaseNumber=00678068, Category__c=Billing}, Event:{Id=00U2f0000018Ly0EAE, Subject=Test event, Type=Email, Status__c=Completed}.
The list<sobject> returns the values from Case and Event object.
But i want to store the field names and its values separately for both case and event in the form of map.
for example map1 should contain key as id, subject,casenumber and value should be new case, 00678068,Billing.
Is it possible?
SobjList=(Case:{Id=5002f0000043zxWAAQ, Subject=New case, CaseNumber=00678068, Category__c=Billing}, Event:{Id=00U2f0000018Ly0EAE, Subject=Test event, Type=Email, Status__c=Completed}.
The list<sobject> returns the values from Case and Event object.
But i want to store the field names and its values separately for both case and event in the form of map.
for example map1 should contain key as id, subject,casenumber and value should be new case, 00678068,Billing.
Is it possible?
for (sObject record : sobjList)
{
Schema.SObjectType sObjectType = record.getSObjectType(); //get record type name, Case or Event
Map<String, Object> fieldsToValue = record.getPopulatedFieldsAsMap(); //get field value map for each record
}
All Answers
for (sObject record : sobjList)
{
Schema.SObjectType sObjectType = record.getSObjectType(); //get record type name, Case or Event
Map<String, Object> fieldsToValue = record.getPopulatedFieldsAsMap(); //get field value map for each record
}
I have a map<string,Map<String,String>>map1 containing the object as the outer key and the value contains field api name and the label (the label is something which i want to use and not the actual field label)
for example: {opportunity={Name=Name information,StageName=Stage Name Details,Channel__c=channel}}.
I have another map<string,Map<String,Object>> map2 containing the object as the outer key and the value contains field api name and its value. for example: {opportunity={Name= new opportunity, stageName= understand customer}.
Now i want to merge the two maps so that map2's value contains field label instead of field api name by fetching the field label from map1 annd the map should look like the following:
map<string,Map<String,String>>map3--> {opportunity={Name information= new opportunity, stage Name Details= understand customer}.
Also, map1 has the label Channel__c=channel but this channel__c field is not present in map2. Hence map3 should contain channel=''.
i need to display map3 in a table format with the field label as the column name and since channel__c is not present in map2, channel column should contain its value as blank in the table.
Is this possible?