function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Calvin SchoenthalerCalvin Schoenthaler 

Auto-Assigning an Entitlement to all Cases

Hello,

I am working in a B2B environment and the vast majority (if not all) of the Cases created are from Web-to-Case submission. I've done some research and it seems that the most efficient way of auto-assigning my Entitlement (only one Entitlement for all Accounts) is through an Apex trigger. Can anyone help with the most efficient way of doing this? Only one Entitlement, wanting to auto-assign to every Case that is created through Web-To-Case.

Thank you!
Adilson Arcoverde JrAdilson Arcoverde Jr
Hi Calvin,

Please try this code:
trigger CaseTrigger on Case ( before insert ) {
    if( Trigger.isBefore && Trigger.isInsert ) {
        List<Entitlement> entitlemens = [Select Id from Entitlement where Account.Name = 'Standard Entitlement Account' LIMIT 1];
        if( entitlemens.size() > 0 ) {
            for( Case newCase : Trigger.new ) {
                newCase.EntitlementId = entitlemens[0].Id;
            }
        }
    }
}

Just replace account matching field to one the fulfills your business requirements.

Hope you find this solution usefeul. If it does please mark as Best Answer to help others too.

Regards.