Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AVX_LeadHelper_cls {
- public static void LeadConvert(list<Lead> lstLead){
- LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
- RecordType rt =[SELECT id , name FROM RecordType WHERE name = 'PyME'];
- List<account> lstcuentas = new List<account>();
- List<contact> lstContacto= new List<Contact>();
- for(Lead l : lstLead){
- Database.LeadConvert lc = new Database.LeadConvert();
- lc.setLeadId(l.id);
- lc.setDoNotCreateOpportunity(true);
- lc.setConvertedStatus(convertStatus.MasterLabel);
- lstCuentas=[SELECT Id,phone,recordTypeId,Correo_electronico__c,Celular__c,calle__c FROM Account WHERE CUIT_CUIL__c =: l.AVX_CUIT__c];
- 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];
- if(lstCuentas.size() !=0 ){
- lc.setAccountId(lstCuentas[0].Id);
- }
- update lstCuentas;
- if(lstContacto.size() != 0){
- lc.setContactId(lstContacto[0].Id);
- }
- update lstContacto;
- Database.convertLead(lc);
- lstCuentas=[SELECT Id,phone,recordTypeId,Correo_electronico__c,calle__c FROM Account WHERE CUIT_CUIL__c =: l.AVX_CUIT__c];
- 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];
- for(Account Cuentas:lstcuentas){
- Cuentas.recordTypeId=rt.Id;
- if(Cuentas.phone == null) {Cuentas.phone=l.Phone;}
- if(Cuentas.Correo_electronico__c == null){Cuentas.Correo_electronico__c=l.Email;}
- 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});}
- }
- update lstCuentas;
- for(Contact Contacto:lstContacto){
- if(Contacto.celular__c==null){Contacto.celular__c=Decimal.ValueOf(l.MobilePhone);}
- if(Contacto.email==null){Contacto.email=l.AVX_Correo_electr_nico__c;}
- 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});}
- }
- update lstContacto;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement