You need to sign in to do that
Don't have an account?

Multikeys map loop
Dear All,
I have the following Case Trigger wherein bulk I create an internal list of cases (from the Trigger.new) and an internal list of accounts for each case with their SalesDivision.
However, I'm confused by the 'for' loop as I get the error messages:
Variable does not exist: Sales_Division__c
DML requires SObject or SObject list type: Map<Id,Account>
Any help?
Thank you
GC
I have the following Case Trigger wherein bulk I create an internal list of cases (from the Trigger.new) and an internal list of accounts for each case with their SalesDivision.
However, I'm confused by the 'for' loop as I get the error messages:
Variable does not exist: Sales_Division__c
DML requires SObject or SObject list type: Map<Id,Account>
Any help?
Thank you
GC
Set<String> setAcountId = new Set<String> (); for(Case obj: Trigger.New){ if(obj.AccountId != null){ setAcountId.add(obj.AccountId); } } //For each Account, find the Sales Division Map<Id,Account> accWithCaseSalesDiv = new Map<Id,Account>( [SELECT Id, Sales_Division__c, (SELECT Id FROM Cases) FROM Account WHERE Id IN : setAcountId ] ); for (Map<Id,Account> obj:accWithCaseSalesDiv ) { if (String.isEmpty(obj.Sales_Division__c)) { obj.Sales_Division__c = 'Americas'; update obj; } } Map<Id,BusinessHours> accBHID = new Map<Id,BusinessHours>( [SELECT Id, name, (SELECT Id FROM Cases) FROM BusinessHours WHERE Id IN : setAcountId ] );
At line no 14, use the below
for (Map<Id,Account> obj:accWithCaseSalesDiv.values() )
AT line no 17, do no update inside for loop. Add it to a list of Account and finally update after the for loop.
Thank you for your reply. I modified the loop in the following way, but I don't uderstand you last part:
I still get the error 'Variable does not exist: Sales_Division__c' which is odd.
You have to change your code like below,
In your existing code, you are doing DML within for loop. It will hit governor limit. So I have moved the DML to outside. You just need to update the MAP.
Please check once below snippet.
Hope this helps you!
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
thank you, that worked better. However, at line 10 of your code, I still get 'Field is not writeable: Account.Sales_Division__c' which I believe has to be moved inside a
block.
Try Below code