+ Start a Discussion
srikanth reddy 27srikanth reddy 27 

write trigger for contact object custom field primary of type checkbox

hi friends ,
pls help me to write following trigger
here contact is having custom field primary of type checkbox
● Each account may have multiple contacts but only one marked “Primary”
● Each account must have 1 primary contact.
● The account should display the name of its primary contact on the account detail screen (i.e. in a field).

Hi Srikanth,


I am trying..i will post the code if I get...but don't forger to post the code here if you get the answer..

srikanth reddy 27srikanth reddy 27
trigger contactupdate on contact_c(after insert){ List c1 =new List(); For (Account a:trigger.new) { if(a.PrimaryContact_Checkbox==true || a.PrimaryContact_Checkbox==false) { List c =[select accountname from contact where c.accountname=a.accountname]; if(c.size()>0) { c1.con='secondary'; } else { c1.con='primary'; } } c1.accountname=a.accountname; c1.contactname=a.contactname; \\some other fields you need } database.insert (c1); }

Hi Srikanth,

Does this code works for you... If could you please paste a screen shot here..

Vidhyasagaran MuralidharanVidhyasagaran Muralidharan
Check this link