You need to sign in to do that
Don't have an account?
Ramana123
Create a field called LiveDate(Date field) on contact. Write a batch to get the contacts whose LiveDate is today and send those contact details to the currently logged in user email .
i wrote below code can anyone help me in this plzz., it is ot working
global class Live_Date_Batch_Class implements Database.Batchable<sObject>{
public List<Contact> conList {get;set;}
global Live_Date_Batch_Class()
{
}
global Database.QueryLocator start(Database.BatchableContext BC)
{
string query = 'select id,LastName from Contact WHERE Live_Date__c = TODAY';
System.debug('aaaaaaaaaaaaaaaaaaaaaaaa'+query) ;
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Contact>scope)
{
Set<Id> convertedIdSet = new Set<Id>();
List<messaging.SingleEmailMessage> emails = new List<messaging.SingleEmailMessage>();
for(Contact contact : scope)
{
convertedIdSet.add(contact.Id);
}
for(Contact contact : scope)
{
conList = ([SELECT FirstName, LastName, Email, Phone, Account.Id
FROM Contact
WHERE Id IN :convertedIdSet] );
}
String userName = UserInfo.getUserName();
User activeUser = [Select Email From User where Username = : userName limit 1];
String userEmail = activeUser.Email;
System.debug('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'+convertedIdSet) ;
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses(new String[] {userEmail});
email.setSubject('+convertedIdSet+');
email.setPlainTextBody('details');
emails.add(email);
String body = 'Contact Details : ' +conList+ ' ';
Messaging.sendEmail(emails);
}
global void finish(Database.BatchableContext BC){
}
}
global class Live_Date_Batch_Class implements Database.Batchable<sObject>{
public List<Contact> conList {get;set;}
global Live_Date_Batch_Class()
{
}
global Database.QueryLocator start(Database.BatchableContext BC)
{
string query = 'select id,LastName from Contact WHERE Live_Date__c = TODAY';
System.debug('aaaaaaaaaaaaaaaaaaaaaaaa'+query) ;
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Contact>scope)
{
Set<Id> convertedIdSet = new Set<Id>();
List<messaging.SingleEmailMessage> emails = new List<messaging.SingleEmailMessage>();
for(Contact contact : scope)
{
convertedIdSet.add(contact.Id);
}
for(Contact contact : scope)
{
conList = ([SELECT FirstName, LastName, Email, Phone, Account.Id
FROM Contact
WHERE Id IN :convertedIdSet] );
}
String userName = UserInfo.getUserName();
User activeUser = [Select Email From User where Username = : userName limit 1];
String userEmail = activeUser.Email;
System.debug('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'+convertedIdSet) ;
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses(new String[] {userEmail});
email.setSubject('+convertedIdSet+');
email.setPlainTextBody('details');
emails.add(email);
String body = 'Contact Details : ' +conList+ ' ';
Messaging.sendEmail(emails);
}
global void finish(Database.BatchableContext BC){
}
}
If you select FirstName, LastName, Email, Phone, Account.Id in your QueryLocator, you won't need to do a second query in your execute method. You would only add to the list you are keeping. Finally, you can build your id set in the finish method with
Map<Id,Contact> contacts = new Map<Id,Contact>(conList);
Set<Id> convertedIdSet = contacts.keySet();