function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dxb_Mandxb_Man 

Need Your help in apex code /Triggers

I have two questions regarding the apex code and triggers,
First question,
What is the apex code or Triggers for preventing an account to have many opportunities? [one account should have one opportunity]
Second question
If I have a field called number of opportunities in XYZ object, so how I can prevent one Account not exceed the number of opportunities. So if the number 5, should one account only have 5 opportunities

THANKS
Guyver118Guyver118

well you would write the trigger at the opportunity end and count how many opportunities the account has then add an error message to the current opporunity, or overwrite the new button and use some javascript or visualforce page which checks how many opportunities there are before creating a new opportunity, if doesn't exceed then redirect them to the new opportunity page.

 

Have some static global variable for this exceed amount or calculate this value for individual accounts.

dxb_Mandxb_Man
First of all Thanks a lot for your reply.

can you send me sample of Trigger code ??

if you don't mind