-
Notifications
You must be signed in to change notification settings - Fork 8
/
ConvertLead
72 lines (61 loc) · 2.47 KB
/
ConvertLead
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Trigger<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
trigger leadConversation on Lead (after update) {
try{
list<Id> lstId= new list<Id>();
if(trigger.isExecuting && trigger.isAfter && trigger.isUpdate){
for(Lead le:trigger.new){
if(le.Status!=trigger.oldmap.get(le.Id).Status){
lstId.add(le.Id);
}
if(lstId.size()>0){
SampleLeadConversion.PerformingConversion(lstId);
}
}
}}catch(DmlException e) {
System.debug('The following exception has occurred: ' + e.getMessage());
system.debug('@@@@:'+e.getLineNumber());
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Trigger Handler<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
public class SampleLeadConversion {
public static void PerformingConversion(list<Id> lstId){
try{
Database.LeadConvert lc = new database.LeadConvert();
for(Id le:lstId)
lc.setLeadId(le);
system.debug('@@@@ lc:'+lc);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 49999];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}catch(exception ex){
system.debug('@@@@ GetMessage: ' +ex.getMessage());
system.debug('@@@@ GetLineNumber:' +ex.getLineNumber());
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Test Class<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@isTest
public class TestConversion {
@TestSetUp public static void CreateTestData(){
try{
Lead le= new Lead();
le.LastName='TestName';
le.Company='TestCompany';
le.Status='Working - Contacted';
insert le;
}catch(exception ex){
system.debug('@@@@ getMessage: '+ex.getMessage());
}
}
@isTest public static void TestMethod1(){
try{
Lead le=[select Id, Status, Company, LastName from Lead Limit 1];
test.startTest();
le.Status='Open - Not Contacted';
update le;
test.StopTest();
}catch(exception ex){
system.debug('@@@@ GetMessage: '+ex.getMessage());
}}
}