Skip to main content
trigger casePhone on Account (After insert,After update) {

    for(Account a : trigger.new){

    list<case> kca = New list<case>([select id,ContactMobile from case where ContactMobile != null And Accountid =: a.id]);

    for(case ca : kca){

        ca.ContactMobile = a.Phone;

        

    }

  }  

}
7 respostas
  1. 29 de jul. de 2017, 15:30
    Hello Kishore,

    I think you want to update the ContactMobile (Contact Mobile) field of case object but this is a standard field and it actually refers to Contact's MobilePhone (Mobile) field. If you update the MobilePhone(Mobile) field of Contact then it automatically update the ContactMobile field of Case. You don't need to write any code for this.

    Hence for this scenario you need to update the MobilePhone field of Contact and it automatically update ContactMobile of Case.

    Find the code below:

    trigger casePhone on Account (After insert,After update) {

        list<case> kca = New list<case>();

        list<Contact> kcon = New list<Contact>();

        list<Contact> lstConupdate = New list<Contact>();

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

        

        for(Account a : trigger.new){       

            kca = [select ContactId, Contact.MobilePhone from case where ContactMobile != null and Accountid =: a.id];

        

            for(Case cs: kca){

                cas.add(cs.ContactId);

            }

        

            kcon = [select id,MobilePhone from Contact where id in: cas];

            for(Contact ca : kcon ){

                ca.MobilePhone = a.Phone;

                lstConupdate.add(ca);                  

            }    

        }

        update lstConupdate;

    }

    But if you dont want to update contact's Mobile number then you can create a custom formula field in case.

    Thanks

    Preyanka