You need to sign in to do that
Don't have an account?
Dippan Patel
Convert list of SObject to Map
Hi,
I have a below list:
List<Sobject> sObj =
Sobject: (Test_Lead_Sources__c:{Id=null, OwnerId=005d0000003vn6BAAQ, IsDeleted=false, Name=test, CreatedDate=null, CreatedById=null, LastModifiedDate=null, LastModifiedById=null, SystemModstamp=null, LastViewedDate=null, LastReferencedDate=null, Primary_Source__c=test, Active__c=false})
It can have any number of records here.
Plus this can have any custom SObject.
I want to get the name of Custom Object here which is Test_Lead_Sources__c and list of all the records in it.
How do I convert this list to map in such a way that I can get name of SObject? Or what is the other possible way?
I have a below list:
List<Sobject> sObj =
Sobject: (Test_Lead_Sources__c:{Id=null, OwnerId=005d0000003vn6BAAQ, IsDeleted=false, Name=test, CreatedDate=null, CreatedById=null, LastModifiedDate=null, LastModifiedById=null, SystemModstamp=null, LastViewedDate=null, LastReferencedDate=null, Primary_Source__c=test, Active__c=false})
It can have any number of records here.
Plus this can have any custom SObject.
I want to get the name of Custom Object here which is Test_Lead_Sources__c and list of all the records in it.
How do I convert this list to map in such a way that I can get name of SObject? Or what is the other possible way?
You can get the name of the Sobject using the method getSObjectType(); Try the below code where I have used Map to store the SobjectType and the List of all records of that Sobject. If this code helps, please mark the answer as best answer as it help others as well.
Thanks
Shruthi