+ Start a Discussion
Raj R.Raj R. 

How to create link to custom object in apex class?


I am trying to use apex trigger to send an email when certain criteria is met for a customObj1__c. The email is supposed to include a link that is something along the lines of "http://cs##.salesforce.com/customObjId". 

How can I send an email where there is a direct link to the record?


Subject: "Some subject"
Link: http://cs01.salesforce.com/customObjId
Best Answer chosen by Raj R.
Tejpal KumawatTejpal Kumawat
Hello friend try this code :
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {

	'tejpalkumawat1991@gmail.com' //your email id
mail.setSubject('Some subject');
String mailBody = 'Link: '+ URL.getSalesforceBaseUrl().toExternalForm()+ '/'+customObjId;
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
Tej Pal Kumawat
Skype : tejpalkumawat1991

If this answers your question mark Best Answer it as solution and then hit Like!