You need to sign in to do that
Don't have an account?
Nicole Young 2
I need help writing an apex test class but not sure where to start. Any help would be greatly appreciated!
global class CreateLeadEmailService implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope){
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
String leadName=email.fromName;
String leadDes=email.plaintextbody;
String leadSub=email.subject;
String leadEmail=email.fromAddress;
Lead l=new Lead(LastName=leadName, Email=leadEmail, Subject_del__c=leadSub, Description=leadDes, Company=leadEmail.split('@').get(1).split('\\.').get(0) );
insert l;
return result;
}
}
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope){
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
String leadName=email.fromName;
String leadDes=email.plaintextbody;
String leadSub=email.subject;
String leadEmail=email.fromAddress;
Lead l=new Lead(LastName=leadName, Email=leadEmail, Subject_del__c=leadSub, Description=leadDes, Company=leadEmail.split('@').get(1).split('\\.').get(0) );
insert l;
return result;
}
}
Please try below test code.
@isTest(SeeAllData=false)
public class CreateLeadEmailServiceTest {
public static testMethod void testEmailService()
{
Messaging.InboundEmail email = new Messaging.InboundEmail() ;
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
email.subject = 'Test Subject';
email.fromAddress = 'xxx@xxx.com';
email.plainTextBody = 'Test PBODY';
email.fromname='Test Name';
CreateLeadEmailService testCreateLeadEmailService = new CreateLeadEmailService();
testCreateLeadEmailService.handleInboundEmail(email, env);
}
}
Regards,
Pawan Kumar
All Answers
Please try below test code.
@isTest(SeeAllData=false)
public class CreateLeadEmailServiceTest {
public static testMethod void testEmailService()
{
Messaging.InboundEmail email = new Messaging.InboundEmail() ;
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
email.subject = 'Test Subject';
email.fromAddress = 'xxx@xxx.com';
email.plainTextBody = 'Test PBODY';
email.fromname='Test Name';
CreateLeadEmailService testCreateLeadEmailService = new CreateLeadEmailService();
testCreateLeadEmailService.handleInboundEmail(email, env);
}
}
Regards,
Pawan Kumar