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

Loading please wait for message in javascript custom button on a standard page

var divback, divpop, img;

if (document.getElementById(‘popDiv’) && document.getElementById(‘backDiv’) && document.getElementById(‘myImg’))
{
divpop = document.getElementById(‘popDiv’);
divback = document.getElementById(‘backDiv’);
img = document.getElementById(‘myImg’);
divback.style.display = ‘block’;
divpop.style.display = ‘block’;
img.style.display = ‘block’;

}
else
{
// Create a background and show the image on top
divpop = document.createElement(‘div’);
divpop.id = ‘popDiv’;
divpop.style.backgroundColor = ‘white’;
divpop.style.borderWidth = ‘0px’;
divpop.style.borderRadius = ‘5px’;
divpop.style.zIndex = ‘9998’;
divpop.style.left = ‘50%’;
divpop.style.top = ‘50%’;
divpop.style.width = ‘115px’;
divpop.style.height = ’50px’;
divpop.style.position = ‘fixed’;
divpop.style.marginLeft = ‘-25px’;
divpop.style.marginTop = ‘-25px’;
document.body.appendChild(divpop);

img = document.createElement(‘img’);
img.id = ‘myImg’;
img.src = ‘/img/loading24.gif’; // your spinner gif
img.style.top = ‘50%’;
img.style.position = ‘fixed’;
img.style.zIndex= ‘9999’;
img.style.left = ‘50%’;
img.style.marginLeft = ‘-12px’;
img.style.marginTop = ‘-12px’;

var div1 = document.createElement(‘div’);
div1.id = ‘msgDiv’;
div1.style.float = ‘right’;
div1.style.marginTop = ’18px’;
div1.style.marginRight = ’20px’;
div1.style.fontSize = ’12px’;
div1.style.fontWeight = ‘700’;
div1.innerHTML = ‘Loading…’;

/* Append loading gif image in parent div */
divpop.appendChild(img);

/* Append message div in parent div */
divpop.appendChild(div1);

divback = document.createElement(‘div’);
divback.id = ‘backDiv’;
divback.style.backgroundColor = ‘black’;
divback.style.opacity = ‘0.80’;
divback.style.filter = ‘alpha(opacity = 30)’;
divback.style.position = ‘fixed’;
divback.style.width = ‘100%’;
divback.style.height = ‘100%’;
divback.style.top = ‘0’;
divback.style.left = ‘0’;
divback.style.zIndex = ‘9997’;
document.body.appendChild(divback);

}
write here your salesforce or sforce code here.