+ Start a Discussion
Venkateshwarrao AdminVenkateshwarrao Admin 

Trigger example

Q) i have two standard objects Account and Contact,Requirment is Display the  Count of Contact on account obj by using custom field Count_of_con. trigger have write. anyone send the code.advanced thanks
Mudasir WaniMudasir Wani
Hey Venkateshwarrao,

Use the rollup summary that is the easiest way to achieve it.

https://help.salesforce.com/apex/HTViewHelpDoc?id=fields_defining_summary_fields.htm&language=en (https://help.salesforce.com/apex/HTViewHelpDoc?id=fields_defining_summary_fields.htm&language=en)

https://help.salesforce.com/apex/HTViewHelpDoc?id=fields_about_roll_up_summary_fields.htm&language=en_US (https://help.salesforce.com/apex/HTViewHelpDoc?id=fields_about_roll_up_summary_fields.htm&language=en_US)

Let me know if you face any issue.

Don't forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can helpn
Anupam RastogiAnupam Rastogi
Hi Venkatesh,

There is no need for writing code if there is Master Detail relationship between Account and Contact. You can create a new roll up summary field on Account that counts the number of child Contact records.


If this solves your problem then please mark it as best answer.
Hi  Venkateshwarrao - The standard Account and Contact are not master detail relationship so you can't have rollup summary field. There are two ways to implement the rollup-summary for the Lookup relationship Thanks,
Venkateshwarrao AdminVenkateshwarrao Admin
Yeah, But when we select the object while creating Rollup summary on account it not shows the contact.its show only oopurtunity object. so we have to write the trigger i thought... Please once try it if any result send back