You need to sign in to do that
Don't have an account?
SV M
Send email with contact details created by lead conversion
Hi, I have written a batch class where I would like to send an email to contact owner with the contact details created by lead conversion.
//Batch Class
global class LeadConversionEmail implements Database.Batchable <sObject>, Database.Stateful{
//public List<Contact> conList {get;set;}
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id, LeadSource, ConvertedDate FROM Lead WHERE ConvertedContactId != NULL';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, Lead[] scope) {
List<Contact> conList = new List<Contact>();
for(Lead ld : scope) {
conList.add([SELECT FirstName, LastName
FROM Contact
WHERE Id IN (SELECT ConvertedContactId FROM Lead)]);
}
}
global void Finish(Database.BatchableContext BC) {
messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String body = 'FirstName ' +conList.FirstName+ 'LastName ' +conList.LastName+ 'done';
}
}
I am getting errors at body saying Variable does not exist. Can you help me resolve the problem and how to send email to contact owner.
Thanks in Advance.
//Batch Class
global class LeadConversionEmail implements Database.Batchable <sObject>, Database.Stateful{
//public List<Contact> conList {get;set;}
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id, LeadSource, ConvertedDate FROM Lead WHERE ConvertedContactId != NULL';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, Lead[] scope) {
List<Contact> conList = new List<Contact>();
for(Lead ld : scope) {
conList.add([SELECT FirstName, LastName
FROM Contact
WHERE Id IN (SELECT ConvertedContactId FROM Lead)]);
}
}
global void Finish(Database.BatchableContext BC) {
messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String body = 'FirstName ' +conList.FirstName+ 'LastName ' +conList.LastName+ 'done';
}
}
I am getting errors at body saying Variable does not exist. Can you help me resolve the problem and how to send email to contact owner.
Thanks in Advance.
Here is the updated Apex Code Which is working fine.
global class LeadConversionEmail implements Database.Batchable <sObject>, Database.Stateful{
public List<Contact> conList {get;set;}
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id, LeadSource, ConvertedDate FROM Lead WHERE ConvertedContactId != NULL';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, Lead[] scope) {
for(Lead ld : scope) {
conList.add([SELECT FirstName, LastName
FROM Contact
WHERE Id IN (SELECT ConvertedContactId FROM Lead)]);
}
}
global void Finish(Database.BatchableContext BC) {
messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String body = 'FirstName ' +conList[0].FirstName+ 'LastName ' +conList[0].LastName+ 'done';
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com