Calling Conga from Apex

Steps:-

1. Create a Remote Site setting record for “https://composer.congamerge.com”.

2. Create the following class.


public static String congaSendMailBackgroundMode(String contactId, String congaTemplateId1, String congaEmailTemplateId1, string subject, string filename, string fromaddress, string sQueryId, string pvz) {

String sessId = UserInfo.getSessionId();
String servUrl = Url.getSalesforceBaseUrl().toExternalForm() + ‘/services/Soap/u/37.0/’ + UserInfo.getOrganizationId();
system.debug(‘*** sessId ‘ + sessId);
system.debug(‘*** servUrl ‘ + servUrl);
String url2 = ‘https://composer.congamerge.com/composer8/index.html’ +
‘?sessionId=’ + sessId +
‘&serverUrl=’ + EncodingUtil.urlEncode(servUrl, ‘UTF-8’);

if (String.isNotBlank(contactId)) {
url2 += ‘&id=’ + contactId;
}
if (String.isNotBlank(congaTemplateId1)) {
url2 += ‘&TemplateId=’ + congaTemplateId1;
}
if (String.isNotBlank(subject)) {
subject = EncodingUtil.urlEncode(subject, ‘UTF-8’);
url2 += ‘&EmailSubject=’ + subject;
}

if (String.isNotBlank(congaEmailTemplateId1)) {
url2 += ‘&EmailTemplateId=’ + congaEmailTemplateId1;
}
if (String.isNotBlank(fromaddress)) {
url2 += ‘&EmailFromID=’ + fromaddress;
}
if (String.isNotBlank(sQueryId) && String.isNotBlank(pvz)) {
url2 += ‘&QueryId=’ + sQueryId + ‘?pv0=’ + pvz;
}
if (String.isNotBlank(filename)) {
filename = EncodingUtil.urlEncode(filename, ‘UTF-8’);
//filename = filename.replace(‘ ‘, ‘%20’);
system.debug(‘*** filename ‘ + filename);
url2 += ‘&OFN=’ + filename;
}

url2 += ‘&SC0=1’+
url2 += ‘&SC1=Attachments’+
‘&defaultPDF=1’ +
‘&DS7=12’ +
‘&APIMODE=12’;

System.debug(‘***URL ‘ + url2);

Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(url2);
req.setMethod(‘GET’);
req.setTimeout(60000);
// Send the request, and return a response
HttpResponse res = http.send(req);

System.debug(‘*** $$$ ‘ + res);
System.debug(‘*** $$$ getStatus ‘ + res.getStatus());
System.debug(‘*** $$$ getBody ‘ + res.getBody());

return res.getStatus() + ‘ => ‘ + res.getBody();

}
calling class method
string rr= congaSendMailBackgroundMode (‘0032K00002F4Tg6′,’a1z2K0000011Rtw’,’a1q2K000000qa2m’,’Email test conga’,’deposion no attendi’,’0D22K000000fxU4′,’a1r2K000007ObAX’,’a072K00000hzw7I’);
system.debug(‘RR ‘+rr);

3.Create Conga Query Record like this.

congaquery

4.Create Conga Template Record like this.

congatemplate

5.Create Conga Email Template Record like this.

congaemailtemplate

 

Conga Parameter

  1. https://support.conga.com/Conga_Composer/Advanced_Composer_Solutions/Composer_Tips_and_Tricks/How_to_Call_Conga_Composer_from_Apex

3 thoughts on “Calling Conga from Apex

Leave a comment