You need to sign in to do that
Don't have an account?
ankur khattri
email to lead not working properly
global class EmailReceive implements Messaging.InboundEmailHandler
{
global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
Messaging.InboundEnvelope env){
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
String[] emailBody = email.plainTextBody.split('\n');
system.debug('------------emailbody------'+emailBody);
//String firstName = emailBody[0].substring(5);
String lastName= emailBody[0].substring(2);
String phoneNumber = emailBody[0].substring(6);
String city = emailBody[0].substring(6);
String status = emailBody[0].substring(3);
String company= emailBody[0].substring(2);
Lead[] newLead = new Lead[0];
try {
if (newLead .size() == 0)
{
newLead.add(new Lead(LastName = lastName,Phone = phoneNumber, City = city,Company=company ));
insert newLead;
}
}
catch (QueryException e) {
}
result.success = true;
return result;
}
}
{
global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
Messaging.InboundEnvelope env){
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
String[] emailBody = email.plainTextBody.split('\n');
system.debug('------------emailbody------'+emailBody);
//String firstName = emailBody[0].substring(5);
String lastName= emailBody[0].substring(2);
String phoneNumber = emailBody[0].substring(6);
String city = emailBody[0].substring(6);
String status = emailBody[0].substring(3);
String company= emailBody[0].substring(2);
Lead[] newLead = new Lead[0];
try {
if (newLead .size() == 0)
{
newLead.add(new Lead(LastName = lastName,Phone = phoneNumber, City = city,Company=company ));
insert newLead;
}
}
catch (QueryException e) {
}
result.success = true;
return result;
}
}
Please use the below code.
global class Email2Lead implements Messaging.InboundEmailHandler
{
global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
Messaging.InboundEnvelope env){
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
String[] emailBody = email.plainTextBody.split('\n');
system.debug('------------emailbody------'+emailBody);
//String firstName = emailBody[0].substring(5);
String lastName= emailBody[0].substring(2);
String phoneNumber = emailBody[0].substring(6);
String city = emailBody[0].substring(6);
String status = emailBody[0].substring(3);
String company= emailBody[0].substring(2);
Lead[] newLead = new Lead[0];
try {
if (newLead .size() == 0)
{
newLead.add(new Lead(LastName = lastName,Phone = phoneNumber, City = city,Company=company ));
insert newLead;
}
}
catch (QueryException e) {
}
result.success = true;
return result;
}
}
Configuring Email Services in Salesforce:
Go to Set up -> Develop -> Email Services.
Click on New Email Service button.
Give a Service Name.
Select the Apex Class we created in above step.
Check Active to TRUE and click on Save.
Please mark it as best answer if it solves your problem.
Thank You.
Please use the below code.
global class Email2Lead implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope env) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
String myPlainText= '';
myPlainText = email.plainTextBody;
List<Lead> leadList = new List<Lead>();
try {
Lead lead = new Lead(Description = myPlainText, Name = email.Subject);
leadList.add(lead);
insert leadList;
System.debug('New lead: ' + leadList);
}
catch (Exception e) {
System.debug('Error is: ' + e);
}
result.success = true;
return result;
}
}
Thank You.
In subject of email - write the lead name
in body of email - write description.
Please mark it as best answer if it helps you,
Thank You.