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
HanumanHanuman 

messaging method to send the vfpage url with the record id

Hi all,

I want to send an email with the vfpage link with the record id after submitting the form. Can we do this in salesforce...?
Can anyone help me over here.

Thanks in advance.
Shiva RajendranShiva Rajendran
Hi hanuman ,
Account acc=[select id from account limit 1];
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
// Set recipients to two contact IDs.
// Replace IDs with valid record IDs in your org.
message.toAddresses = new String[] { 'someEmail@gmail.com', 'someEmail@gmail.com' };
message.subject = 'LinktoVFPage';
String baseUrl={!LEFT($CurrentPage.URL,FIND('/',$CurrentPage.URL,9))};

String contentData=' All contents     ' ;
contentData+= ' <a href="'+baseUrl+'/apex/vfPage/'+'?id=acc.id">click to go to vf page  </a>';

message.setHtmlBody=contentData;
Messaging.SingleEmailMessage[] messages = 
    new List<Messaging.SingleEmailMessage> {message};
         Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
if (results[0].success) {
    System.debug('The email was sent successfully.');
} else {
    System.debug('The email failed to send: '
          + results[0].errors[0].message);
}

This code should work ( I haven't tested though) ,Let me know if you face any further issues.
Also do note that the page redirects to the login of salesforce first ,only if the login is successful ,then the vf page is displayed.
Thanks and Regards,
Shiva RV