You need to sign in to do that
Don't have an account?
Andrew Hoban 6
Having a limit on the amount of times a picklist values can be selected.
Hi all,
is there a way to have a limit on the amount of times a value in a picklist field can be selected? I have an object called Software_Assets__c and a vaule in a picklist called Microsoft Office.
I want the Microsoft Office value to only be selected 10 times.
Many thanks
is there a way to have a limit on the amount of times a value in a picklist field can be selected? I have an object called Software_Assets__c and a vaule in a picklist called Microsoft Office.
I want the Microsoft Office value to only be selected 10 times.
Many thanks
Please find the sample code,this might help you.
trigger stopOpportunityCreation on Opportunity(before insert,before update){
Integer count =[select count() from opportunity where LeadSource='Advertisement'];
for(Opportunity a:trigger.new){
if(count==10&&a.LeadSource=='Advertisement'){
a.addError('Please chose some other pick-list Values');
}
}
}
All Answers
you can create a field in Software_Assets__c object as integer.Let's say it counter__c
Then each time when user selects the picklist value is "Microsoft Office", then increment a counter and update the value of counter__c.
If it reaches 10 then throw an error and stops the execution.
Cheers
Swagata
Thanks
Please find the sample code,this might help you.
trigger stopOpportunityCreation on Opportunity(before insert,before update){
Integer count =[select count() from opportunity where LeadSource='Advertisement'];
for(Opportunity a:trigger.new){
if(count==10&&a.LeadSource=='Advertisement'){
a.addError('Please chose some other pick-list Values');
}
}
}