You need to sign in to do that
Don't have an account?
Souls
Initial term of field expression must be a concrete SObject
I have written an After Insert trigger on Case that re-assigns AccountId and Contact Id associated wiith the case based on if the case is created by a customer portal user or not.
The trigger will not compile because of an error that I don't quite understand here: Initial term of field expression must be a concrete SObject: LIST<Case>
It fails where I'm extracting the new Id from a map of Accounts keyed by a custom field: SSNumber__c and try to assign that Id to the Case.AccountId field (see ==> below). What am I doing wrong?
trigger AfterInsertCase on Case (after insert) { List<Id> lstCases = new List<Id>(); List<String>lstSSNumbers=new List<String>();
// Find cases created by Customer Portals for (Case caseObj:Trigger.new) { if(caseObj.Account.IsCustomerPortal==true){ lstCases.add(caseObj.Id); lstSSNumbers.add(caseObj.SSNumber__c); } } // Create a map with the AccountID's keyed by SSNumber__c Map<String,Account>MapAccBySSNumber=new Map<String,Account>(); List<Account>lstAcc=new List<Account>([Select Id, SSNumber__c from Account where SSNumber__c IN:lstSSNumbers]); for(Account ac:lstAcc){ MapAccBySSNumber.put(ac.SSNumber__c,ac); } // Update the Case object with new references to Contact and Account List<Case>lstCaseInfo=new List<Case>([Select Id, AccountId, ContactId, SSNumber__c from Case where Id IN :lstCases]); list<Case>lstCasesToUpdate=new List<Case>(); for(Case cse: lstCaseInfo){ ==> cse.AccountId = MapAccBySSNumber.get(lstCaseInfo.SSNumber__c).Id; ==> cse.ContactId=MapAccBySSNumber.get(lstCaseInfo.SSNumber__c).Id; lstCasesToUpdate.add(cse); } update lstCasesToUpdate; }
Modify like this
One issue is there in the line
cse.ContactId=MapAccBySSNumber.get(cse.SSNumber__c).Id;
Here you are assigning accountid to contactid field which is not possible. So please check your code.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
All Answers
The error message tells you exactly the offending object.
Surely it will complain for you are using (as mentioned in the error) List<Case>.SSNumber__c to get an item from the map:
cse.AccountId = MapAccBySSNumber.get(lstCaseInfo.SSNumber__c).Id;
cse.ContactId=MapAccBySSNumber.get(lstCaseInfo.SSNumber__c).Id;
Modify like this
One issue is there in the line
cse.ContactId=MapAccBySSNumber.get(cse.SSNumber__c).Id;
Here you are assigning accountid to contactid field which is not possible. So please check your code.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Ouch!
I see my mistake, and it hurts ;)
I had re-written the code anyway to this format (essentially doing the same thing but with a line or two less):