Activity Forums Salesforce® Discussions How to write a Salesforce trigger for below given scenario? Reply To: How to write a Salesforce trigger for below given scenario?

  • Raghav Chaturvedi

    Member
    July 13, 2017 at 2:40 pm

    trigger concatinat on Contact (after insert,after update)
    {
    List accList = new List();
    set S = new Set();
    for(contact con : Trigger.new)
    {
    S.add(con.accountid);
    }
    Map mv = new Map([SELECT id,name
    FROM account WHERE Id IN : S]);

    for(contact cont : Trigger.new)
    {
    Account acct = new Account();
    acct.id = mv.get(cont.accountid).id;
    acct.name = mv.get(cont.accountid).name + '-' +cont.lastname;
    accList.add(acct);

    }
    update accList;
    }