Skip to main content
David Kemp 님이 #Apex에 질문했습니다
Hi,

I have a trigger that updates a Case's BusinessHours field based on the Country of the Account, if I update the Business Hours field in an After Insert trigger, then the field is updated but the Milestones (which are created on Insert) refer to the default Business Hours, not unreasonably!

Is it possible to get the country field from the parent Account in a Before Insert Trigger, if so, how would I do that?

Many thanks,

David
답변 3개
  1. 2015년 5월 5일 오전 10:19

    David - Try the below code to get the lookup field values in the before insert operation

    trigger MyTrigger on Case(before insert) {

    Set<Id> AccountIds = new Set<Id>();

    for (Case cs: Trigger.new) {

    if (cs.AccountId != null) {

    AccountIds.add(cs.AccountId);

    }

    }

    Map<Id, AccountId> accountEntries = new Map<Id, Account>(

    [select Id,Name from Account where id in :AccountIds]

    );

    for (Case caseRec : Trigger.new) {

    String accountName = accountEntries.get(caseRec .AccountId).Name; //Getting Account name, similarly you can get other field value as well

    //your logic

    }

    }

     
0/9000