Skip to main content
Hi

I have two objects one is contact and another one is Case.but in Case object Email field is there whenever user enter email something like test@sony.com . after @ value updated to contact name like sony.com updated to contact name in contact object,how can i write the trigger.

Thanks In Advance

NRField Update In contact name
3 respuestas
  1. 28 ago 2015, 6:26
    Hi,

    try this below code....

    trigger Sample_tri on Case (after insert) {

    if(trigger.isInsert && trigger.isAfter){

    Map<ID,String>cids=new Map<ID,String>();

    for(Case c:trigger.new){

    if(c.ContactId!=null && c.email__c!=null){

    String[] arrName =c.email__c.split('@');

    system.debug('--------'+arrName[1]);

    cids.put(c.ContactId,arrName[1]);

    }

    }

    List<Contact>ccc=[select id,lastname from Contact where id IN:cids.keySet()];

    for(contact c:ccc){

    c.lastName=cids.get(c.id);

    }

    update ccc;

    }

    }

     
0/9000