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
sfdcianpsfdcianp 

limiting the promotions to three

i have promotion object as an related list in the campaign object.

i need to enter only 3 promotions for that campaign , if at all i am entering another promotion it chould throw an error

please suggest the way to do this...

 

thanks in advance
sfdcinap

Best Answer chosen by Admin (Salesforce Developers) 
Marko LamotMarko Lamot

Hello,

 

you should implement the apex trigger on promotion object where you would check the number of promotions and throw an error.

 

Alternatively you can do also the following - only possible if you have master-detail relation between campaign and promotion:

- create a rollup summary "number of promotions" field on campaign

- use that  field in validation rule of promotion object.

 

 

All Answers

Marko LamotMarko Lamot

Hello,

 

you should implement the apex trigger on promotion object where you would check the number of promotions and throw an error.

 

Alternatively you can do also the following - only possible if you have master-detail relation between campaign and promotion:

- create a rollup summary "number of promotions" field on campaign

- use that  field in validation rule of promotion object.

 

 

This was selected as the best answer
sandeep@Salesforcesandeep@Salesforce

See if your Promotion is having master detail relation ship with campaign then you can write rollup summry field which will count number of child records ( promotion records ) unser Campaign and then write a validation that if parent record's rollup feld value is more then 3 then child record will not be saved.

 

Second way is trigger on before inserting o count existing child records and if it is more then 3 then will not allow user to insert a new child record on campaing.