You need to sign in to do that
Don't have an account?
Ramana V
Test Class for Inbound Email Service
Hi All,
I have written following inbound email service for lead object.
Can someone please hepl me with test class for this?
Thanks in Advance
Regards,
Ramana
I have written following inbound email service for lead object.
global class LeadServices implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env) { Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); string emailbody = email.plaintextbody; string emailsubject = email.subject; string subToCompare = emailsubject.Substring(emailsubject.indexof('ref :') + 5).trim(); try { lead l = [SELECT Id, Name, Email FROM lead WHERE id = : subToCompare]; // Add a new Task to the lead record we just found above. Task newTask = new Task(); newTask.Description = emailbody; newTask.Priority = 'Normal'; newTask.Status = 'Inbound Email'; newTask.Subject = emailsubject; newTask.IsReminderSet = true; newTask.ReminderDateTime = System.now(); newTask.WhoId = l.Id; Insert newTask; } catch(QueryException e) { System.debug('Issue: ' + e); } result.success = true; return result; } }I am have having 55% code coverage now.
Can someone please hepl me with test class for this?
Thanks in Advance
Regards,
Ramana
I have gone through your problem please refer bellow code:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
All Answers
Greetings to you!
You are using emailsubject.Substring(emailsubject.indexof('ref :') + 5).trim(); as an Id to get the lead record which is not a valid id.
Please refer to the below links which might help you further with the above requirement.
http://amitsalesforce.blogspot.com/2016/12/test-class-for-email-service-test-class.html
http://www.sfdcmeet.com/development/inbound-email-service/
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
I have gone through your problem please refer bellow code:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com