+ Start a Discussion
Ashok S 7Ashok S 7 

how to override standard salesforce button

Hai guys .
I have one requirment. THat is When create a button for standard or custom object .When i click that button an email is send to the record owner.
How it is possible.cani any one help me
Amit Chaudhary 8Amit Chaudhary 8
Overriding Standard button with visualforce page
https://help.salesforce.com/HTViewHelpDoc?id=links_override_considerations.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=links_override_considerations.htm&language=en_US)

Please let us know if above link will help u
Ashok S 7Ashok S 7
But i want when i click a button automatically email is sent to the record owner
Amit Chaudhary 8Amit Chaudhary 8
Please try below.
Example 1:- http://salesforce.stackexchange.com/questions/17444/how-to-send-email-on-custom-button-using-javascript
// single mail request

var singleRequest = new sforce.SingleEmailMessage();
singleRequest.replyTo = "jsmith@acme.com";
singleRequest.subject = "sent through ajax test driver";

singleRequest.plainTextBody = "this test went through ajax";
singleRequest.toAddresses = ["noone@nowhere.com"];

// mass mail request - need to get email template ID

var queryResponse = sforce.connection.query("select id from emailtemplate");
var templatedId = queryResponse.getArray("records")[0].Id;
var massRequest = new sforce.MassEmailMessage();
massRequest.targetObjectIds = [globalContact.id];
massRequest.replyTo = "jsmith@acme.com";
massRequest.subject = "sent through ajax test driver";
massRequest.templateId = templateId;

var sendMailRes = sforce.connection.sendEmail([singleRequest, massRequest]);

Example 2: -
Simply go to Setup | Customize | Contacts | Buttons, Links, and Actions, and create this as a new button or link of the "URL" type (you can use the same window). Change the Template ID to match the email template you'd like to auto-select.

If you want a one-click send feature, you'd need Visualforce.

Here's a sample Visualforce page:
<apex:page standardController="Contact" extensions="sendEmail" action="{!sendEmail}">
    <apex:pageMessages />
And associated controller:
public with sharing class sendEmail {

    ApexPages.StandardController controller;

    public sendEmail(ApexPages.StandardController controller) {
        this.controller = controller;

    public PageReference sendEmail() {
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { message });
        return controller.view();

Exmple 2:-
Updated: Here's a JavaScript-only version. Note that this will use API calls in addition to Mass Email limits, while Visualforce will only use Mass Email limits.
(function() {
sforce.connection.sessionId = "{!$Api.Session_ID}";
var message = new sforce.SingleEmailMessage();
message.replyTo = "{!$User.Email}";
message.targetObjectId = "{!Contact.Id}";
message.templateId = "00X30000000h4jF";
var result = sforce.connection.sendEmail([message]);
  if(result[0].success) {
     alert("I sent the email as you requested, master.");
  } else {
     alert("I had a booboo.");
Please let us know if this will help u

Amit Chaudhary