Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. /***************************************************************************************************************
  2. * Avanxo
  3. * @author Denise Volpe, Franco Molfino
  4. * Proyecto: PyMe
  5. * Descripción: Conversion de Lead en Cuenta y Contacto
  6. * Cambios (Version)
  7. * -------------------------------------------
  8. * No. Fecha Autor Descripción
  9. * ----- ---------- --------------------- ---------------
  10. * @version 1.0 16/05/2019 Denise Volpe, Franco Molfino Clase que se encarga de convertir una Lead en un contacto y una cuenta.
  11. ****************************************************************************************************************/
  12. public class AVX_LeadHelper_cls {
  13.  
  14.  
  15.  
  16. //Metodo modificado por Denise
  17. public static void LeadConvert2(list<Lead> lstLead){
  18.  
  19. LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
  20. RecordType rt =[SELECT id , name FROM RecordType WHERE name = 'PyME'];
  21. List<account> lstcuentas = new List<account>();
  22. List<contact> lstContacto= new List<Contact>();
  23.  
  24.  
  25. for(Lead l : lstLead){
  26. Database.LeadConvert lc = new Database.LeadConvert();
  27. lc.setLeadId(l.id);
  28. lc.setDoNotCreateOpportunity(true);
  29. lc.setConvertedStatus(convertStatus.MasterLabel);
  30.  
  31.  
  32.  
  33. lstCuentas=[SELECT Id,phone,recordTypeId,Correo_electronico__c,Celular__c,calle__c FROM Account WHERE CUIT_CUIL__c =: l.AVX_CUIT__c];
  34. 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];
  35.  
  36.  
  37. if(lstCuentas.size() !=0 ){
  38.  
  39. lc.setAccountId(lstCuentas[0].Id);
  40.  
  41. }
  42.  
  43. update lstCuentas;
  44.  
  45.  
  46. if(lstContacto.size() != 0){
  47. lc.setContactId(lstContacto[0].Id);
  48.  
  49. }
  50. update lstContacto;
  51.  
  52. Database.convertLead(lc);
  53.  
  54.  
  55. lstCuentas=[SELECT Id,phone,recordTypeId,Correo_electronico__c,calle__c FROM Account WHERE CUIT_CUIL__c =: l.AVX_CUIT__c];
  56. 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];
  57.  
  58. for(Account Cuentas:lstcuentas){
  59. Cuentas.recordTypeId=rt.Id;
  60.  
  61. if(Cuentas.phone == null){
  62. Cuentas.phone=l.Phone;
  63. }
  64. if(Cuentas.Correo_electronico__c == null){
  65. Cuentas.Correo_electronico__c=l.email;
  66. }
  67. if(Cuentas.Calle__c == null){
  68. String.format('{0}\n{1}\n{2}\n{3}',new String[]{l.street,l.state,l.PostalCode,l.country});
  69. }
  70. update Cuentas;
  71. }
  72.  
  73.  
  74.  
  75. for(Contact Contacto:lstContacto){
  76. if(Contacto.phone == null){
  77. Contacto.phone=l.MobilePhone;
  78. }
  79. if(Contacto.Email == null){
  80. Contacto.Email=l.AVX_Correo_electr_nico__c;
  81. }
  82. if(Contacto.Calle__c == null){
  83. String.format('{0}\n{1}\n{2}\n{3}',new String[]{l.street,l.state,l.PostalCode,l.country});
  84. }
  85. update Contacto;
  86. }
  87.  
  88.  
  89. }
  90.  
  91.  
  92. }
  93. //Metodo hecho por Franco
  94. public static void LeadConvert(list<Lead> lstLead){
  95.  
  96. LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
  97. RecordType rt =[SELECT id , name FROM RecordType WHERE name = 'PyME'];
  98. List<account> lstcuentas = new List<account>();
  99. List<contact> lstContacto= new List<Contact>();
  100.  
  101.  
  102.  
  103.  
  104. for(Lead l : lstLead){
  105. Database.LeadConvert lc = new Database.LeadConvert();
  106. lc.setLeadId(l.id);
  107. lc.setDoNotCreateOpportunity(true);
  108. lc.setConvertedStatus(convertStatus.MasterLabel);
  109.  
  110. lstCuentas=[SELECT Id,phone,recordTypeId,Correo_electronico__c,calle__c FROM Account WHERE CUIT_CUIL__c =: l.AVX_CUIT__c];
  111. 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];
  112.  
  113. if(lstCuentas.size() != 0){
  114. lc.setAccountId(lstCuentas[0].Id);
  115.  
  116. }
  117. update lstCuentas;
  118. if(lstContacto.size() != 0){
  119. lc.setContactId(lstContacto[0].Id);
  120.  
  121. }
  122. update lstContacto;
  123.  
  124. Database.convertLead(lc);
  125.  
  126.  
  127. }
  128. }
  129.  
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement