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 EMAIL SERVICE (EMAIL TO LEAD) CLASS IN ANONYMOUS WINDOW

global class CreateLeadExample implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){ 
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
String myPlainText= '';
myPlainText = email.plainTextBody; 
Lead[] leads = [SELECT Id, Name, Email FROM Lead WHERE Email = :email.fromAddress];
if (leads.size() == 0) { 
Lead newLead = new Lead(Email = email.fromAddress, LastName = 'From Email', Company = 'From Email'); 
insert newLead;
System.debug('New Lead record: ' + newLead ); }
else {
System.debug('Incoming email duplicates existing Lead record(s): ' + leads ); } 
result.success = true; 
return result;
}
}
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Siva,

You can call this class from anonomous window as below.
 
Messaging.InboundEmail email = new Messaging.InboundEmail() ;
 Messaging.InboundEnvelope env    = new Messaging.InboundEnvelope();
 email.subject = 'test unsubscribe test';
 email.fromAddress = 'usesasassr@acme.com';
CreateLeadExample cs= new CreateLeadExample();
cs.handleInboundEmail(email,env);

Let me know if you face any issues.

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

Thanks,