You need to sign in to do that
Don't have an account?
sfdcianp
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
trigger createPromotion on Promotion(before insert){
for(Promotion p:Trigger.new){
// get all the promotions for a campaign
Integer pCount = [select id from promotion where campaignid =: p.campaignid].count();
if(pCount==3){
p.addError('Only 3 promotions can be added to the campaign');
}
}
}
Integer pCount = [select count() from promotion where campaignid=:p.campaignid];
Syed ishaq , yes you can use a trigger. But the trigger has to be bulkified and you should never write a query in a for loop. You might cross the governor limits.
Can go through this link : http://wiki.developerforce.com/page/Apex_Code_Best_Practices
The bulkified code can be desgined something like this. This is when you try to insert promotion records in bulk .