function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

previous lead record will update when currently inserted record throughs an error how?

firstly i prevented duplicates on email when ever i insert new record if email field value match with previous values then it throug an error at that time i want to update any number field to increnent by 1(any field of previous recod) of lead that alredy contains this email id.please help me for this.
To accomplish this first check for duplicate emails in the before insert, before update trigger. Follow the code as explained at the link .

In the code shown in the above link, after fetching all contacts, put an update statement to update the number field on the matching records.

Hope this helps.
trigger countinc on Lead (before insert) {
    public List<lead> le{get;set;}
    public lead l1{get;set;}
    if (Trigger.isBefore) {
        le=[select email from lead];
    for (lead s:le)
    for(Lead record :
           l1=[select NumberOfEmployees from lead where];
              l1.NumberOfEmployees ++;
              update l1;


see this code once if then we click on save button it will through error message,at the same time record will be  update that is my recuirement.

in this trigger record of NumberOfEmployees is incrementing by one it is showing in system.debug but not reflected to actual record why means new record in not submitting.