function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Siva Krishna KondapalliSiva Krishna Kondapalli 

how to call a inboundemailhandler method from helper class to trigger how to call a inboundemailhandler method from handler class to trigger...?

User-added image
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Siva,

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?

mukesh guptamukesh gupta
Hi Siva,

Please use below code in your helper 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.


Siva Krishna KondapalliSiva Krishna Kondapalli

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; } }
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Siva,

You have to define both the parameters first and then call the method as below fro anonomoous window.
Messaging.InboundEmail email = new Messaging.InboundEmail() ;
 Messaging.InboundEnvelope env    = new Messaging.InboundEnvelope();
 email.subject = 'test unsubscribe test';
 email.fromAddress = '';
CreateLeadExample cs= new CreateLeadExample();

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.