• manish Deshmukh 6
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
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
 
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 
   ]
);