Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. public class RelatedContacts
  2. {
  3. public Static List<Contact> Relatedcontacts = new List<Contact>();
  4. public static integer count=0;
  5. public Static List<Lead> OtherLeads = new List<Lead>();
  6. public static void LeadConvertion(Map<Id,Id> RelatedLeads)
  7. {
  8. List<Database.LeadConvert> converts = new List<Database.LeadConvert>();
  9. String convertedStatus = [SELECT MasterLabel FROM LeadStatus WHERE IsConverted = TRUE LIMIT 1].MasterLabel;
  10. for(Lead Ls:[Select id,Parent_Lead__c from lead where Parent_Lead__c=:RelatedLeads.keyset()])
  11. {
  12. If(Ls.Parent_Lead__c <> null && count <20)
  13. {
  14. Database.LeadConvert lc = new Database.LeadConvert();
  15. lc.setLeadId(Ls.Id);
  16. lc.setConvertedStatus(convertedStatus);
  17. lc.setAccountId(RelatedLeads.get(Ls.Parent_Lead__c));
  18. lc.setDoNotCreateOpportunity(true);
  19. converts.add(lc);
  20. count =count+1;
  21. }
  22. if(Ls.Parent_Lead__c <> null && count >=20)
  23. {
  24. //Lead lss=new lead();
  25. Lead ll=new Lead(Id = Ls.Id);
  26. //ll.id=Ls.id;
  27. Count=Count+1;
  28. //ll.Status='Not Visible';
  29. ll.Parent_Lead__c='';
  30. OtherLeads.add(ll);
  31. //OtherLeads.add(lss);
  32. }
  33. }
  34. If(!OtherLeads.isEmpty())
  35. {
  36. Update OtherLeads;
  37. }
  38. Database.convertLead(converts, false);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement