+ Start a Discussion
Aryan JhaAryan Jha 

i have an error

trigger leadwithaccount on Lead (before insert) {
    List<Lead>leadwithdata=new List<Lead>();
   for(Lead l:Trigger.new)
   {
       if(l.AnnualRevenue=50000)
       {
           l.adderror('amount is less');
           leadwithdata.add(l);
           
}
   }
    insert leadwithdata;

}
AbhinavAbhinav (Salesforce Developers) 
Hi Aryan,

Please elaborate  your questions .Specify the error which you are getting.

Thanks!
Aryan JhaAryan Jha
The trigger is not working. I have to make lead annual amount which is greater thean 50000 else shows error if less than
AbhinavAbhinav (Salesforce Developers) 
You mean only those lead should be inserted whose AnnualRevenue>=50000 or else we should throw error?

#SampleCode

trigger leadwithaccount on Lead (before insert) {
    
   for(Lead l:Trigger.new)
   {
       if(l.AnnualRevenue < 50000)
       {
           l.adderror('amount is less');
           
}
   }
}

If it helps mark it as best Answer.

Thanks!
Suraj Tripathi 47Suraj Tripathi 47
Hi Aryan,
Greetings!

Please try this code.
trigger leadwithaccount on Lead (before insert, before update) { 
    List<Lead> leadwithdata = new List<Lead>();
    for(Lead l:Trigger.new) { 
        if(l.AnnualRevenue < 50000) { 
            l.AnnualRevenue.adderror( 'Amount is less');
        }
    }
}

If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi
Aryan JhaAryan Jha
Thank you for your response.