You need to sign in to do that
Don't have an account?
Peter Cowen
trigger to add entitlement to case
I am trying to build a trigger that adds the entitlement to the case when the account name is populated.
So far I have
trigger defaultEntitlement on Case (Before Insert, Before Update) {
List <Entitlement> entls = [Select
e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
From Entitlement e
Where
e.AccountId in : acctIds 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;
When saving I get a Compile Error: Variable does not exist: acctIds.
Will this trigger assign the entitlement to the case and 2 is there anything else i need to add to the trigger
So far I have
trigger defaultEntitlement on Case (Before Insert, Before Update) {
List <Entitlement> entls = [Select
e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
From Entitlement e
Where
e.AccountId in : acctIds 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;
When saving I get a Compile Error: Variable does not exist: acctIds.
Will this trigger assign the entitlement to the case and 2 is there anything else i need to add to the trigger
(you were also missing an opening bracket, and I tried to pair them all up for you).
Otherwise, this will do what you are asking ultimately.. it goes through all the cases and copies whatever it find in the entitlement field into the case... (it also copied the AssetId in too).
It's not quite how I might do it, you might even be able to do this with workflow instead to be fair?