You need to sign in to do that
Don't have an account?
Vinicius Passos
Help needed for auto associate entitlement to email-to-case
Hi, I'm not a Salesforce Developer but I'm working in apex code to automatically associate an entitlement to email-to case.
I found this code below, but I'm facing some problems
In line 5: Variable does not exist: contactIds
In line 25: Variable does not exist: accId
trigger DefaultEntitlement on Case (Before Insert) { List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e Where e.ContactId in : contactIds And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today]; if(entlContacts.isEmpty()==false){ for(Case c : Trigger.new){ if(c.EntitlementId == null && c.ContactId != null){ for(EntitlementContact ec:entlContacts){ if(ec.ContactId==c.ContactId){ c.EntitlementId = ec.EntitlementId; if(c.AssetId==null && ec.Entitlement.AssetId!=null) c.AssetId=ec.Entitlement.AssetId; break; } } } } } else{ List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId From Entitlement e Where e.AccountId in :accId And e.EndDate >= Today And e.StartDate <= Today]; if(entls.isEmpty()==false){ for(Case c : Trigger.new){ if(c.EntitlementId == null && c.AccountId != null){ for(Entitlement e:entls){ if(e.AccountId==c.AccountId){ c.EntitlementId = e.Id; if(c.AssetId==null && e.AssetId!=null) c.AssetId=e.AssetId; break; } } } } } } }
Please try with below code.
Please let me know incase if you need any assistnace.
All Answers
Please try with below code.
Please let me know incase if you need any assistnace.
Hi Prakash Nawale, I did the changes that you mentioned and solve the problems. But unfortunelly the code doesn't work
The case remains without entitlement when create by email-to-case
Can you please create Entitlement data to meet conidtions in code before creating case from email to Case.
But is not clearly to me what is wrong
In Trigger system first checks case has account or contact yes then find entilement based on account or contact if match found then use that entitlement id to put in case.entitlement.
It's very simple logic.
if you need more details please ping me on Skype : nawaleprakash and mark this as best answer.
Regards,
Prakash