0

I have created an trigger which is sent an email to the user every time a user is created and they are welcomed and reminded to complete the KYC Process.

How should I send a URL in the body of the mail which redirects back to the Detail page of the Customer object?

This is my code:

trigger EmailTriggerOnCustomer on Customer__c (before insert) {
    //List<Customer__c> customerEmail = [SELECT id, Email__C from Customer__c];
    List<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();
    
    for(Customer__c cus : trigger.new){
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        //List of people receiving the mail
        List<String> sendTo = new List<String>();
        sendTo.add(cus.Email__C);
        mail.setToAddresses(sendTo);
        
        //Set where the email is sent from
        mail.setReplyTo('[email protected]');
        mail.setSenderDisplayName('Bank Administrator');
        
        //set email content
        mail.setSubject('Fill your KYC Details for Verification');
        String body = 'Dear ' + cus.Name + ', ';
        body += '<br> Please complete your KYC Verification process by filling the details to open your Bank Account.';
        
        mail.setHtmlBody(body);
        
        mails.add(mail);
        
    }
    if(mails.size() > 0)
        Messaging.sendEmail(mails);
}
 

and i want to redirect back to this page. The customer shall have redirect back to its own detail page. Please help. - enter image description here

1 Answer 1

2

Please drop a Salesforce link into your body details as follows,

//set email content
        mail.setSubject('Fill your KYC Details for Verification');
        String body = 'Dear ' + cus.Name + ', ';
        body += '<br> Please complete your KYC Verification process by filling the details to open your Bank Account.';
        body += '<br> https://yourinstance.my.salesforce.com/'+cus.id;

Then the receiver user can able to redirect into details page by using that link.

Please let me know if it helps.

9
  • it is not reading the id - empathetic-panda-i5er71-dev-ed.lightning.force.com/lightning/r/…
    – sfdxnewbie
    Oct 12, 2021 at 6:20
  • You're going to send an email to user once after the customer record is created right?
    – Raj
    Oct 12, 2021 at 6:31
  • If it's Yes, Please make your trigger fire in "After Insert". then you can able to get the ID Value without issue.
    – Raj
    Oct 12, 2021 at 6:33
  • Yes you're right. That was my use case. And after trigger helped fetch the id. But now its showing another error. When the URL is clicked its saying- 'This record is no longer available. Ask your administrator for help.'
    – sfdxnewbie
    Oct 12, 2021 at 7:33
  • Please check the record is whether available in your org or any user or other process will delete the record.
    – Raj
    Oct 12, 2021 at 7:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .