2016-04-27 39 views

回答

0

請看這段代碼。希望這會幫助你。

trigger CaseTrigger on Case (after insert) { 
    Map<Id, String> contactIdToCaseNumberMap = new Map<Id, String>(); 

    for (Case c : Trigger.new) { 
     if (String.isNotBlank(c.ContactId)) { 
      contactIdToCaseNumberMap.put(c.ContactId, c.CaseNumber); 
     } 
    } 

    List<Contact> contactsToUpdate = [SELECT Id, Last_Case_Number_Solved__c FROM Contact WHERE Id IN :contactIdToCaseNumberMap.keySet()]; 
    for (Contact cont : contactsToUpdate) { 
     cont.Last_Case_Number_Solved__c = contactIdToCaseNumberMap.get(cont.Id); 
    } 
    update contactsToUpdate; 
} 
相關問題