You need to sign in to do that
Don't have an account?
sailer
VF Page template for scheduling
Hi Everyone,
I have req ,when the field in the custom object is checked , i need to send that details to the mail for that records ,where we have custom field.
I wrote the code by VF template and components ,in the VF template i am getting all the records that have checked,but i need one records and send the mail for that record.
and i am scheduling the code that run every day to pick that template and send out the mail
Here is the code.
######Compnent Class#####
<apex:component controller="acctTemplt" access="global">
<apex:attribute name="AcctId" type="Id" description="Id of the account" />
<table border = "2" cellspacing = "5">
<tr>
<td>Name</td>
<td>Status</td>
</tr>
<apex:repeat value="{!opptys}" var="o">
<tr>
<td>{!o.Name}</td>
<td>{!o.Mail_Response__c }</td>
</tr>
</apex:repeat>
</table>
</apex:component>
########Apex Class#######
public class acctTemplt
{
public List<String> usr_email{get;set;}
public List<Property_Obj__c> usr{get;set;} //
public Map<string,string> Map_usr{get;set;}
public List<Property_Obj__c> getopptys()
{
usr=new List<Property_Obj__c>();
usr_email=new List<String>();
List<Property_Obj__c> oppty;
Map_usr=new Map<string,string>();
oppty = [SELECT Id,Name, Mail_Response__c,Listing_Sales_Associate_Email__c,Status__c FROM Property_Obj__c WHERE Mail_Response__c =true ];
return oppty;
}
}
#####Scheduler Class#######
/*
Created for Followp and to send the mail
*/
global class RemainderMailFrequency implements Schedulable
{
public List<Property_Obj__c> usr{get;set;} //
public List<String> usr_email{get;set;}
Property_Obj__c updateproperty= new Property_Obj__c();
public Map<string,string> Map_usr{get;set;}
global void execute(SchedulableContext ctx)
{
usr=new List<Property_Obj__c>();
usr_email=new List<String>();
usr.clear();
usr_email.clear();
usr=[select id, Status__c,Name,Mail_Response__c,Listing_Sales_Associate_Email__c from Property_Obj__c where Mail_Response__c=true ];
Map_usr=new Map<string,string>();
for(Property_Obj__c u:usr)
{
system.debug('__id______'+u.id+'___________Email______'+u.Listing_Sales_Associate_Email__c+'_________DATE_____'+u.Status__c);
Map_usr.put(u.id,u.Listing_Sales_Associate_Email__c);
if(u.Listing_Sales_Associate_Email__c!=null)
usr_email.add(u.Listing_Sales_Associate_Email__c);
}
if(usr_email.size()>0)
{
sendmail(usr_email);
}
}
public void sendmail(List<String> str)
{
EmailTemplate et = [SELECT id,HtmlValue,Body,Subject ,Name FROM EmailTemplate WHERE Name = 'RemainderMailVF'];
system.debug('Template values for sending the mail__________________ '+et.Subject);
Messaging.Singleemailmessage email = new Messaging.Singleemailmessage();
String [] toaddress=str;
String[] ccAddresses=new String[]{'test@gmail.com'};
email.setTemplateId(et.Id);
email.setTargetObjectId('005800000059yaE');
email.setSaveAsActivity(false);
email.setToAddresses(toaddress);
email.setCcAddresses(ccAddresses);
Messaging.sendEmail(new Messaging.Singleemailmessage[] { email });
}
}
and my o/p Look like below ,but there will be one Name for one email id associated i need to this alone
Name Status
13 true
12 true
15 true
14 true
Regards
Sailer
I have req ,when the field in the custom object is checked , i need to send that details to the mail for that records ,where we have custom field.
I wrote the code by VF template and components ,in the VF template i am getting all the records that have checked,but i need one records and send the mail for that record.
and i am scheduling the code that run every day to pick that template and send out the mail
Here is the code.
######Compnent Class#####
<apex:component controller="acctTemplt" access="global">
<apex:attribute name="AcctId" type="Id" description="Id of the account" />
<table border = "2" cellspacing = "5">
<tr>
<td>Name</td>
<td>Status</td>
</tr>
<apex:repeat value="{!opptys}" var="o">
<tr>
<td>{!o.Name}</td>
<td>{!o.Mail_Response__c }</td>
</tr>
</apex:repeat>
</table>
</apex:component>
########Apex Class#######
public class acctTemplt
{
public List<String> usr_email{get;set;}
public List<Property_Obj__c> usr{get;set;} //
public Map<string,string> Map_usr{get;set;}
public List<Property_Obj__c> getopptys()
{
usr=new List<Property_Obj__c>();
usr_email=new List<String>();
List<Property_Obj__c> oppty;
Map_usr=new Map<string,string>();
oppty = [SELECT Id,Name, Mail_Response__c,Listing_Sales_Associate_Email__c,Status__c FROM Property_Obj__c WHERE Mail_Response__c =true ];
return oppty;
}
}
#####Scheduler Class#######
/*
Created for Followp and to send the mail
*/
global class RemainderMailFrequency implements Schedulable
{
public List<Property_Obj__c> usr{get;set;} //
public List<String> usr_email{get;set;}
Property_Obj__c updateproperty= new Property_Obj__c();
public Map<string,string> Map_usr{get;set;}
global void execute(SchedulableContext ctx)
{
usr=new List<Property_Obj__c>();
usr_email=new List<String>();
usr.clear();
usr_email.clear();
usr=[select id, Status__c,Name,Mail_Response__c,Listing_Sales_Associate_Email__c from Property_Obj__c where Mail_Response__c=true ];
Map_usr=new Map<string,string>();
for(Property_Obj__c u:usr)
{
system.debug('__id______'+u.id+'___________Email______'+u.Listing_Sales_Associate_Email__c+'_________DATE_____'+u.Status__c);
Map_usr.put(u.id,u.Listing_Sales_Associate_Email__c);
if(u.Listing_Sales_Associate_Email__c!=null)
usr_email.add(u.Listing_Sales_Associate_Email__c);
}
if(usr_email.size()>0)
{
sendmail(usr_email);
}
}
public void sendmail(List<String> str)
{
EmailTemplate et = [SELECT id,HtmlValue,Body,Subject ,Name FROM EmailTemplate WHERE Name = 'RemainderMailVF'];
system.debug('Template values for sending the mail__________________ '+et.Subject);
Messaging.Singleemailmessage email = new Messaging.Singleemailmessage();
String [] toaddress=str;
String[] ccAddresses=new String[]{'test@gmail.com'};
email.setTemplateId(et.Id);
email.setTargetObjectId('005800000059yaE');
email.setSaveAsActivity(false);
email.setToAddresses(toaddress);
email.setCcAddresses(ccAddresses);
Messaging.sendEmail(new Messaging.Singleemailmessage[] { email });
}
}
and my o/p Look like below ,but there will be one Name for one email id associated i need to this alone
Name Status
13 true
12 true
15 true
14 true
Regards
Sailer
Sending email when a particular field is checked, cab be achieved by Workflow email alerts. Wondering why have you opted for VF templates, please elaborate.
In Workflow you can not schedule, is that the reason you have taken this approach?