+ Start a Discussion
Anju Alexander 5Anju Alexander 5 

Trigger

Hi All,

I have written a trigger on case. The trigger was to populate the entitlement field(which is a lookup to entitlement) with the entitlements of the Accounts .Here entitlements are child objects of accounts. If I am creating a case from the console the entitlement field is getting populated with the value. But if I am creating a case from web to case form the entitlement field is not getting populated with the value,..even if a match is found between the contacts and accounts.

Please help.

Thanks.
SonamSonam (Salesforce Developers) 
Does the trigger have any condition on the source of the case? Can you please share the code of trigger so I can test it at my end..
Anju Alexander 5Anju Alexander 5
Hi Sonam,

This is my trigger code:

trigger EntitlementTrigger on Case (before insert) {

Map<id,Account> accountMap=new Map<id,Account>();
Map<id,Entitlement> entMap=new Map<id,Entitlement>();

Set<id> caseSet=new Set<id>(); 
List<Case> caseList=new List<Case>();

if((Trigger.isInsert) && (Trigger.isBefore)){
for(Case c:trigger.new)
{
caseMap.add(c.accountId);    
}

for(Account c:[select id,name from Account where Id in :caseSet])
{
accountMap.put(c.id,c);    
System.debug('.......'+accountMap);
}


for(Entitlement e:[select id,name,AccountId from Entitlement where accountId in :accountMap.keySet()])
{
entMap.put(e.accountId,e);    
System.debug('.......'+entMap);
}

for(Case c: Trigger.new)
{
    if(c.EntitlementId==null && c.accountId!=null && c.accountId==accountMap.get(c.accountID).ID)
    {
        if(entMap.containsKey(c.accountId))
        {

        c.EntitlementId=entMap.get(c.accountId).id;
        caseList.add(c);
        }
    }
}
}
}


Thanks.
Anju Alexander 5Anju Alexander 5
Hi All,

Please help me to find the solution for this....I am still not getting it..

Thanks