+ Start a Discussion
srilakshmi1.387861669756762E12srilakshmi1.387861669756762E12 

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

firstly i prevented duplicates on email field.so 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.
Ramu_SFDCRamu_SFDC
To accomplish this first check for duplicate emails in the before insert, before update trigger. Follow the code as explained at the link https://success.salesforce.com/answers?id=90630000000h5ymAAA .

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.
srilakshmi1.387861669756762E12srilakshmi1.387861669756762E12
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];
   
        system.debug('111111111111'+le);
    }
    for (lead s:le)
    {  
    for(Lead record : Trigger.new)
    {
       
        if(record.email==s.email)
        {
           system.debug('44444'+s.email);
           System.debug('666666666666666'+(record.Email));
           l1=[select NumberOfEmployees from lead where email=:s.email];
           system.debug('333333333'+l1.NumberOfEmployees);
           if(l1.NumberOfEmployees!=null)
           {
              l1.NumberOfEmployees ++;
              system.debug('4444444'+l1.NumberOfEmployees);
              update l1;
             
           }
         
        }
         
       
    }
     
    }
   

}


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

in this trigger s.email 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.