SHARE
TWEET

Untitled

a guest Jun 17th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class AVX_LeadHelper_cls {
  2.    
  3.  
  4.      public static void LeadConvert(list<Lead> lstLead){
  5.        
  6.         LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
  7.         RecordType rt =[SELECT id , name FROM RecordType WHERE name = 'PyME'];
  8.         List<account> lstcuentas = new List<account>();
  9.         List<contact> lstContacto= new List<Contact>();
  10.        
  11.        
  12.        
  13.         for(Lead l : lstLead){
  14.             Database.LeadConvert lc = new Database.LeadConvert();
  15.             lc.setLeadId(l.id);
  16.             lc.setDoNotCreateOpportunity(true);
  17.             lc.setConvertedStatus(convertStatus.MasterLabel);
  18.            
  19.            
  20.            
  21.             lstCuentas=[SELECT Id,phone,recordTypeId,Correo_electronico__c,Celular__c,calle__c FROM Account WHERE CUIT_CUIL__c =: l.AVX_CUIT__c];
  22.             lstContacto = [SELECT Id, accountId, account.CUIT_CUIL__c,celular__c,email,calle__c,phone FROM Contact WHERE AVX_DNI__c =:l.AVX_DNI__c and account.CUIT_CUIL__c =: l.AVX_CUIT__c];
  23.            
  24.            
  25.             if(lstCuentas.size() !=0 ){
  26.                
  27.                     lc.setAccountId(lstCuentas[0].Id);
  28.                    
  29.             }
  30.             update lstCuentas;
  31.            
  32.            
  33.             if(lstContacto.size() != 0){
  34.                 lc.setContactId(lstContacto[0].Id);
  35.                
  36.             }
  37.             update lstContacto;
  38.            
  39.             Database.convertLead(lc);
  40.            
  41.            lstCuentas=[SELECT Id,phone,recordTypeId,Correo_electronico__c,calle__c FROM Account WHERE CUIT_CUIL__c =: l.AVX_CUIT__c];
  42.             lstContacto = [SELECT Id, accountId, account.CUIT_CUIL__c,celular__c,email,calle__c,phone FROM Contact WHERE AVX_DNI__c =:l.AVX_DNI__c and account.CUIT_CUIL__c =: l.AVX_CUIT__c];
  43.          
  44.                 for(Account Cuentas:lstcuentas){
  45.                     Cuentas.recordTypeId=rt.Id;
  46.                     if(Cuentas.phone == null) {Cuentas.phone=l.Phone;}
  47.                     if(Cuentas.Correo_electronico__c == null){Cuentas.Correo_electronico__c=l.Email;}
  48.                     if(Cuentas.Calle__c == null) {Cuentas.Calle__c= String.format('{0}\n{1}\n{2}\n{3}',new String[]{l.street,l.state,l.PostalCode,l.country});}
  49.                 }
  50.                
  51.            
  52.             update lstCuentas;
  53.          
  54.                 for(Contact Contacto:lstContacto){
  55.                     if(Contacto.celular__c==null){Contacto.celular__c=Decimal.ValueOf(l.MobilePhone);}
  56.                     if(Contacto.email==null){Contacto.email=l.AVX_Correo_electr_nico__c;}
  57.                     if(Contacto.calle__c==null){Contacto.calle__c=String.format('{0}\n{1}\n{2}\n{3}',new String[]{l.street,l.state,l.PostalCode,l.country});}
  58.                 }
  59.            
  60.             update lstContacto;
  61.            
  62.            
  63.            
  64.            
  65.         }
  66.        
  67.        
  68.     }
  69.    
  70.    
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top