2016-04-27 14 views

Antwort

0

Bitte schauen Sie sich diesen Code an. Hoffe das wird dir helfen.

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; 
}