I want to write a trigger on Contact-when contact is created and if primary checkbox is true update parent account phone with contact phone. I am new to coding Here is my code...
trigger PrimaryContactValidation on Contact (before update,before insert) {
set<id> accountids=new set<id>();
for(contact con:trigger.new){
if(con.is_primary__c==true)
{
accountids.add(con.accountid);
}
}
map<id,account> mapacc=new map<id,account>([select id,(select accountid from contacts) from account where id in :accountids]);
list<string>acclist=new list<string>();
for(contact acc:trigger.new){
if(mapacc.containsKey(acc.accountid)){
acclist.add(acc.accountid);
}
}
for(account ac:acclist){
}
}
I am not able to write exact trigger.