1

I'm trying to use Dotmailer's external dynamic content to render dynamic content for an email from sfdc data

I initally almost had this working using a visualforce page exposed in a force.com site, but the vf page includes javascript in the headers, that I was unable to remove, which caused rendering issues in a small number of cases.

Dotmailer support indicates that the expected response is a html page. So I'm trying to use an apex REST endpoint to return a HTML page. I've set one up here, which is set to return a string as a response. The string is not rendered in the email, as the page is returning xml.

I'm probably missing something basic as my background knowledge on how http requests work is limited, but any suggestions on how to address this are appreciated. The rather elementary code for my endpoint is below:

@RestResource(urlMapping='/Applications/*') 
global with sharing class applicationEndpoint {    

    @HttpGet
    global static string GetTitle() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        res.addHeader('Content-type', 'text/html; charset=utf-8');        
        String resp = 'session title';
        return resp;
    }

}
0

1 Answer 1

0

Without Rest

I don't think you need a rest service. If you send a request to a normal HTML page you get the content on the page. If you add query parameters to your URL you can communicate with a controller on the page (in this case apex) to dynamically generate your content.

If you're having issues with the scrips, remove or modify them or clone the page and then remove them from the new page.

With Rest

If you absolutely can't do that and have to do it via rest I think you're on the right track.

I don't think you're actually getting XML. I think your mistake is that you're viewing it in a browser. When I made a request in postman all the response contained was

"session title"

When viewed in Chrome, the content of the page is wrapped inside of XML, probably because it doesn't know what to do with a plain string.

If you update your code to deliver a valid HTML string you might get a different result. Something like <html><head></head><body><h1>Hello World!</h1><hr/><p>WE DID IT!!</p></body></html>

Update

Instead of returning a string, return a valid rest response. Try:

global static RestResponse GetTitle() {
    RestRequest req = RestContext.request;
    RestResponse res = RestContext.response;
    res.addHeader('Content-type', 'text/html; charset=utf-8');
    res.setBody('<html><head></head><body><h1>Hello World!</h1><hr/><p>WE DID IT!!</p></body></html>');
    return resp;
}
11
  • thanks unfortunately there is no way to remove the scripts. they are included on any visualforce page even w/ show header +++ set to off/false. if you view the source of the page in the browser you can see it starts with xml version="1.0" encoding="UTF-8 - and i think that is the piece i need to change. but i'm not reallys ure how. i'll try including the full html string and see.
    – gorav
    Commented Aug 30, 2018 at 18:43
  • Finish reading my answer. I explained to you why it shows as XML and what you need to do.
    – gNerb
    Commented Aug 30, 2018 at 18:44
  • thanks i will try to see how it resolves in dotmailer again when presenting the string w the html tags.
    – gorav
    Commented Aug 30, 2018 at 18:45
  • I see that you updated it and in my postman test the page is wrapped in quotes which prevent it from being rendered correctly
    – gNerb
    Commented Aug 30, 2018 at 18:48
  • After checking postman it shows the content type as json still, it appears to not be honoring your content type. I updated my answer with something else for you to try
    – gNerb
    Commented Aug 30, 2018 at 18:51

You must log in to answer this question.

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