I have a batch which I use to send emails to contacts.

Every contact should have a different template - So I Created a body and subject in my apex class which every contact will have his unique body- for Example:

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            String body = '';
            body+= proposalInformation(Some SObject);

private String proposalInformation(SObject a){
            body += '<p style="font-weight:bold; color:red; text-align: center;">' + a.Typo__c  +  '</p>' ;
            body+= '</br></br>';
            body += '<p style="font-weight:bold; text-align: center;">' + a.FirstName__c  +  '</p>' ;
            body+= '</br></br>';
            body+= '<p style="text-align: center;">Submission Deadline : ' + a.date_and_time__c + '</p>';
            body+= '</br></br>';
            body+= '<p style="text-align: center;"> Description : ' + a.Description__c+ '</p>';
            body+= '</br></br>';
            body+= '<p style="text-align: center;">Amount  : ' + a.Total_amount__c+ '</p>';
            body+= '</br></br>';
            body+= ' <p style="text-align: center;">Links : ' + a.link__c+ '</p>';
            body+= '</br></br>';
            body+= '<p style="text-align: center;"> ---------------------------------------------------------- </p>';
            body+= '</br></br>';

  return body;

If I want to add a global < style > < / style > and than add a class to the divs instead of the inline css, how can I do it?

For example:


and then : body += '<p class="cc">' + a.Typo__c + '</p>' ;

Is that a way to involve Bootstrap here for pretty border around the email?

Is there a way to define an email template and in the code just replace the body?

Thanks in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.