function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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 (

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:-
// single mail request

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

singleRequest.plainTextBody = "this test went through ajax";
singleRequest.toAddresses = [""];

// 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 = [];
massRequest.replyTo = "";
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