Can you post the code because screenshot may not help and also can you confirm from which trigger you are expecting it to call and which contexts do you want to call this class?
Messaging.inboundEmail email = new Messaging.inboundEmail();
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
// populate email and env with appropriate data/headers
// then you can...
handleInboundEmail(email, env);
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
HOW TO CALL THIS CLASS IN TRIGGER (BEFORE INSERT) OR IN ANONYMOUS WINDOW ....?
global class CreateLeadExample implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){ // Create an InboundEmailResult object for returning the result of the // Apex Email Service Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); String myPlainText= ''; // myPlainText = email.plainTextBody; // Check for existing leads with this email address Lead[] leads = [SELECT Id, Name, Email FROM Lead WHERE Email = :email.fromAddress]; if (leads.size() == 0) { // New Lead object to be created - set LastName and Company to // dummy values for simplicity Lead newLead = new Lead(Email = email.fromAddress, LastName = 'From Email', Company = 'From Email'); // Insert a new lead insert newLead; System.debug('New Lead record: ' + newLead ); } else { System.debug('Incoming email duplicates existing Lead record(s): ' + leads ); } // Set the result to true. No need to send an email back to the user // with an error message esult.success = true; // Return the result for the Apex Email Service return result; } }
Can you post the code because screenshot may not help and also can you confirm from which trigger you are expecting it to call and which contexts do you want to call this class?
Thanks,
Please use below code in your helper class:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
global class CreateLeadExample implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){
// Create an InboundEmailResult object for returning the result of the // Apex Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
String myPlainText= ''; //
myPlainText = email.plainTextBody; // Check for existing leads with this email address
Lead[] leads = [SELECT Id, Name, Email FROM Lead WHERE Email = :email.fromAddress];
if (leads.size() == 0) { // New Lead object to be created - set LastName and Company to // dummy values for simplicity
Lead newLead = new Lead(Email = email.fromAddress, LastName = 'From Email', Company = 'From Email'); // Insert a new lead insert newLead; System.debug('New Lead record: ' + newLead ); }
else { System.debug('Incoming email duplicates existing Lead record(s): ' + leads ); } // Set the result to true. No need to send an email back to the user // with an error message
esult.success = true; // Return the result for the Apex Email Service
return result; } }
You have to define both the parameters first and then call the method as below fro anonomoous window.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,