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
SFDev@321SFDev@321 

ERROR in custom button to send mail to owner on custom object.

I have a custom object- "TEST" on which i want custom BUTTON-"CMail" on it which will send an email to the owner of that record

===================================================

 

My custom Button CMail:- code

 

{!REQUIRESCRIPT("/soap/ajax/16.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/16.0/apex.js")} 
var ret = sforce.apex.execute("Sendemailbutton" ,"CMail", {}); 
window.location.reload(); 
alert(ret);

 

 

Class:- 

 

global class Sendemailbuttonidepot{

WebService static void UrgetoPSM()
{

test__c con=[Select id,Owner.email,OwnerId from test_c where OwnerId!=null limit 1];
EmailTemplate et=[Select Id,Name,HtmlValue,Encoding,FolderId, Body,Subject From EmailTemplate where name='Salesforce customer' limit 1];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

String[] toAddresses = new String[]{'abc@gmail.com'};
//string test=con.Owner.email;
mail.setTargetObjectId(con.OwnerId);
mail.setSubject('User XYZ');
mail.saveAsActivity = false;
mail.setToAddresses(toAddresses);
system.debug('Hanamnth'+mail);
mail.setPlainTextBody('HI we are Testing');
mail.setTemplateId(et.id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}

 

 

But i'm not able to send the mail to the owner of the record can any1 help me where i'm wrong......