How to get my desired Map id list sobject salesforce?

236    Asked by AntonyBence in Salesforce , Asked on Apr 17, 2023

I have below code where I face error as incompatible type. Can someone please help me resolve it? I can't get how to populate it.

Apex Code

 Map> accATLMap = new Map>();
.........
for(Account_Territory_Loader_vod__c atl: atlList) {
 if(accATLMap.get(atl.account_vod__c) == null)
 accATLMap.put(atl.account_vod__c,atl); // This line gets error out
}
Answered by Clare Matthews

you can use below code to get your desired Map id list sobject salesforce: -


for(Account_Territory_Loader_vod__c atl: atlList) {
    if(accATLMap.containsKey(atl.account_vod__c) && accATLMap.get(atl.account_vod__c) != null) {
        List lst_terr = accATLMap.get(atl.account_vod__c);
        lst_terr.add(atl);
        accATLMap.put(atl.account_vod__c,lst_terr);
    }
    else {
        accATLMap.put(atl.account_vod__c, new List {atl});
    }
}

I hope it solves your purpose.



Your Answer

Interviews

Parent Categories