opportunity records

Mail a Table of Opportunity Records With a Link of Detail Page | Salesforce Tutorial

In this blog, we have checked the closedDate of the whole Opportunity records and sent a mail of all opportunities whose closedDate is less than today to the Opportunity owner with the link of a Detail page for changing the closedDate of the Opportunity in a table format.

for(string key :map2.keyset()){
    htmlBody = 'Hi  ' +map2.get(key)+ '<br /> \nPlease review the below opportunities which are closing today and kindly take the required actions \n <br /> <table border="1" style="border-collapse: collapse"><tr><th>Name</th><th>StageName</th><th>CloseDate</th><th>Opportunity Link</th></tr>';
    for(Opportunity opp:map1.get(key)){
            system.debug('strlist====1' +strlist);
        String baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
        oppLink = opp.id;
        htmlBody += '<tr><td>' + oppName +  '</td><td>' + oppStageName +'</td><td>' + oppCloseDate + '</td><td>' +'/'+baseUrl + '/' +oppLink + '</td></tr>';
    htmlBody += '</table> <br /> \n Thank You <br /> \n Salesforce Automation \n';
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    //  system.debug('mailtoset++'+ mail.setToAddresses(strlist));
    mail.setSubject('Opportunity with close date today');
    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>{mail};  

dont miss out iconCheck out another amazing blog by Aditya here: Why You Should Consider Investing In Salesforce Lightning

If you have any questions, let me know in the comment section.        


Popular Salesforce Blogs