Hello I will be glad if anyone can help me. I created a custom number field on the Lead Object. Sales_Ready_Counter__c
I wrote a trigger to increment Sales_Ready_Counter__c by 1 whenever a custom picklist (Sales_Ready__c) value changes as follows:
If Sales_Ready__c == 'yes' then increment Sales_Ready_Counter__c by 1
Sales_Ready_Counter__c starts from Zero (0). I want it to start from 1 instead of starting from 0. I can't figure out what I am doing wrong, please help review, my code is below:
trigger updateLeadSalesReadyCounter on Lead (before insert, before update) {
for(Lead l :Trigger.new)
try
{
Lead oldSR = Trigger.oldMap.get(l.Id);
Boolean oldStatus = oldSR.Sales_Ready__c.equals('Yes');
Boolean newStatus = l.Sales_Ready__c.equals('Yes');
if (!oldStatus && newStatus)
{
if(l.Sales_Ready__c != Null)
{
if(l.Sales_Ready__c == 'Yes')
{
l.Sales_Ready_Counter__c = l.Sales_Ready_Counter__c != Null ? l.Sales_Ready_Counter__c +1: 0;
}
}
}
}
catch(System.NullPointerException e)
{
//
}
}