You need to sign in to do that
Don't have an account?
Dekor
Setting apex trigger not to create entitlement automatically if entitlement already exists
During setting up of entitlements I've created an Apex trigger that automatically assigns an entitlement to new/updated accounts where type = customer. This is working, however I've discovered that everytime an account is updated, another entitlement is automatically created.
So I need to modify my trigger to first check there isn't an existing entitlement set up. Below is the trigger and I've added:
(entitlement.accountid != account.id)
However this doesn't seem to do the task. Any ideas on how I can modify my trigger to not create the entitlement when there is already an existing entitlement in the entitlement table matching the account ID on the account I'm updating.
So I need to modify my trigger to first check there isn't an existing entitlement set up. Below is the trigger and I've added:
(entitlement.accountid != account.id)
However this doesn't seem to do the task. Any ideas on how I can modify my trigger to not create the entitlement when there is already an existing entitlement in the entitlement table matching the account ID on the account I'm updating.
trigger CreateEntitlement on Account (after insert,before update) { List<Entitlement> createentitlement = new List <Entitlement> {}; for (Account acc : trigger.new) { if ((acc.type == 'customer')&&(entitlement.accountid != account.id)) /* If the Account type is set to customer and no entitlement already exists*/ { createentitlement.add(new Entitlement ( Name = acc.name, /* Give a standard name*/ AccountId = acc.Id, /* Link the Entitlement to the account */ SlaProcessId = '55220000000L9IJAA0', /* Link it to a defined entitlement process */ StartDate = system.Today(), Type = 'Phone Support', BusinessHoursId = '01m200000009dGQAAY' )); } } try { insert createentitlement ; } catch (Exception Ex) { system.debug(Ex); } }
All Answers