You need to sign in to do that
Don't have an account?
Rob Lilley
custom email button on custom object - To address default to email address on object
Hello, I wonder if anyone could help on this please. Fairly new to the coding on buttons.
I have a custom object 'Match' which is not related to Contacts. I'm trying to create a custom button that has two functions:
location.replace('/email/author/emailauthor.jsp?retURL=/{!Match__c.Id}&p3_lkid={!Match__c.Id}&rtype=003&template_id=00X0Y000000IQvm');
It appears to me with (1) above that I can add parameters to default the 'Additional To' and 'CC' to the value you in Volunteer_Email__c but not the To address. (I think it it is looking for a contact which in this case I do not have).
Many thanks for any advice, Rob
I have a custom object 'Match' which is not related to Contacts. I'm trying to create a custom button that has two functions:
- Default the To email address to the value in the Volunteer_Email__c on the Match object
- When email is sent update the Volunteer_Email_Sent_Date__c on the Match object to the date sent
location.replace('/email/author/emailauthor.jsp?retURL=/{!Match__c.Id}&p3_lkid={!Match__c.Id}&rtype=003&template_id=00X0Y000000IQvm');
It appears to me with (1) above that I can add parameters to default the 'Additional To' and 'CC' to the value you in Volunteer_Email__c but not the To address. (I think it it is looking for a contact which in this case I do not have).
Many thanks for any advice, Rob
Hi Lilley
I have done your senario so for this you need to follow some steps.
steps 1 : Create Detail Page Button on Match object.
step 2 : select Behavior of custom button execute javascript .
step 3 : write this code which i mentioned.
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var returnFlag = sforce.apex.execute("testhost.SendEmailUsingWebserive","sendEmail",{matchid:'{!match__c.Id}'});
location.reload(true);
step 4 : save this and set this cutom button at layout
step 5 : create class and put code i mentioned below.
global class SendEmailUsingWebserive
{
webService static void sendEmail(String matchid)
{
string varconid = matchid;
List<match__C>listofmatch =[select id , Volunteer_Email__c , Name from match__C where id =: varconid];
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
if(listofmatch .size()>0){
for(match__C obj : listofmatch ){
if(obj.Volunteer_Email__c != null){
obj.testhost__Volunteer_Email_Sent_Date_c__c=system.today();
// Email code //
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add(obj .Email);
mail.setToAddresses(sendTo );
mail.setSenderDisplayName('Details');
List<String> ccTo = new List<String>();
mail.setCcAddresses(ccTo);
mail.setSubject('Hi ');
String body = 'Hi' +obj.Name +', ';
body += '<br/>';
body += '<br/>';
body += 'Congratulations on your acceptance has been done<br/>';
mail.setHtmlBody(body);
mails.add(mail);
}
}
}
if(mails.size()>0){
Messaging.sendEmail(mails);
update listofContact ;
}
}
}
o/p : See here is custom button whenever i will click here email will be go and here is one date field which will update as per your requirement.
:
Many thanks for your update, much appreciated and will try this tomorrow when back in office, best wishes, Rob
thanks Rob
If you have any issue let me know .
I have just tried saving the class and I receive an error:
Error: Compile Error: Variable does not exist: listofContact at line 33 column 24 (which I think is referrring to update listofContact ;?)
Many thanks, Rob
REQUIRESCRIPT no longer working with Winter 16
As per release winter 16 release notes: http://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/salesforce_release_notes.htm
REQUIRESCRIPT no longer executes JavaScript on Page Load.
I guess therefore:
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
No longer works and needs something else?
Best wishes, Rob