+ Start a Discussion
sra gowthamsra gowtham 

I need this one trigger code

I need a trigger code for picklist my picklist items are a)20, 2).50 ,3)60....one can select mulitiple options .if count is  less than  or equel to 100 it will saves .if count is greater than 100 it  have throw a message as the value must be less than 100...i need a trigger code for this
Akshay_DhimanAkshay_Dhiman
Hi gowtham,

Just Try this below code,
Hope it is going to work for you, Modify it according to your need -- 
 
trigger AccTriggerPicklist on Account (before insert) {
    for(Account acc : trigger.New)
    {
        Integer sum = 0;
        List<String> tmpString = new List<String>();
        tmpString.addAll(acc.PickList__c.split(';'));
        for(String str : tmpString)
        {
            sum += Integer.valueof(str.trim());
        }
        if(sum>100)
        {
            acc.addError('Cannot Insert account with count greater than 100');
        }
    }
}


Thanks 
Akshay