+ Start a Discussion
raj jordanraj jordan 

i have two custom filelds on account object and two custom fields on another custom object with same api names if i insert an account the values of that fields should be display in custom object also  can you please help me

HI ALL,
i have two custom filelds on account object and two custom fields on another custom object with same api names if i insert an account the values of that fields should be display in custom object also 
can you please help me
Manoj DeshmukhManoj Deshmukh

Hi Raj

you can achieve this through workflow with field update ||  Process Builder..

Workflow Criteria:

Contact phone is null and evrytime record is create and it's edited

Action: Field Update: 

Conatct Phone = Account.Phone

Or Using Trigger also you can update field.
Please try below trigger.

trigger AccountUpdate2 on Contact (after insert, after update) {
    Map<Id, String> accountIdAndPhoneMap = New Map<Id, String>();
    Set<ID> aID = new Set<ID>();
    List<Account> acclist = new List<Account>(); 
        for(Contact con:Trigger.new)
        {
            if(con.Phone != null){
                aID.add(con.AccountId);
                accountIdAndPhoneMap.put(con.AccountId, con.Phone);
            }
        }
        for(Account a:[select id, Phone, (select id, Phone from contacts) from Account where ID IN: aID])
        {
            a.Phone = accountIdAndPhoneMap.get(a.id);
            acclist.add(a);
        }
        update acclist;    
}

Please mark it as solved, it will help others
Thank you,
Manoj