does anyone know if it is possible possible to trigger Conga action(generate document/send email with attachment/create attachment) from apex code - best would be trigger or batch. Example will be appreciated.

  • 1
    Have you looked at Conga Conductor? I've not used it but came across it recently: congamerge.com/products/composer/add-ons
    – Girbot
    Mar 10, 2016 at 19:43
  • No, I am looking for free solution. As far as I know it was possible to use callout to generate document in conga 7 - but I can't achievw this in conga 8.... Mar 10, 2016 at 19:48
  • 5
    (1) did you see success.salesforce.com/… ?; (2) Conga has superb support, have you asked them?
    – cropredy
    Mar 10, 2016 at 20:08
  • 4
    Artur -- I 'love' "bothering" Conga Support because a) they are super friendly (and it is not bothersome to them) , b) they know tricks that aren't always documented and c) I learn something each time. Unlike support at say, Big Company X, where you might rather put pins through your eyes, Conga support is terrific - and if you are a licensed user, free.
    – cropredy
    Mar 13, 2016 at 19:00
  • 1
    I totally would bother them , some of the folks there need to get on salesforce and start supporting salesforce cases right away. They are super technical and courteous. Do not waste your time waiting, contact them right away
    – Rao
    Mar 16, 2016 at 18:55

3 Answers 3


According to @CongaPete in this thread: Run Conga Composer (release 8) in background mode via HTTP Callout, you cannot do this in Conga Composer 8. Instead, you can still use the Conga 7 endpoint https://www.appextremes.com/apps/conga/pm.aspx and the same querystring parameters.

One note, you will also need to use the old Conga 7 style merge syntax, not the new Text-Based Merge Fields.

I recommend the DS7=5 parameter as well.

  • Is it possible to this via trigger? I assume you will have to use a future method. But that is a asynchronous. And hence would not have the sessionID that conga needs.
    – RajeshShah
    Jul 3, 2019 at 15:06

It is possible. You need to purchase the Conga Workflow package.

See info here: https://support.getconga.com/Conga_Composer/Conga_Workflow


Some working code to invoke through apex with conga 8 since nobody else seemed to share here yet :) I almost believed it wasn't possible after seeing responses above but I was able to make it work!

private static final String CONGA_ENDPOINT = 'https://composer.congamerge.com/composer8/index.html?';
String templateId = [SELECT APXTConga4__Key__c FROM APXTConga4__Conga_Template__c WHERE APXTConga4__Name__c = 'ISR Report' LIMIT 1].APXTConga4__Key__c;
String accountId = 'ExAmPlEaCcOuNtId';    // query the master record ID you need here, just keeping it simple for example
String sessionId = UserInfo.getSessionId();
String servUrl = System.Url.getSalesforceBaseUrl().toExternalForm() + '/services/Soap/u/14.0/' + UserInfo.getOrganizationId();
String endpoint = CONGA_ENDPOINT + 'sessionId=' + sessionId + '&serverUrl=' + EncodingUtil.urlEncode(servUrl, 'UTF-8');
//endpoint += '&id=' + accountId + '&TemplateId=' + templateId + '&defaultPDF=1' + '&APIMODE=1';    // if there are issues, Conga recommends trying to remove the DS7 (background mode) param
endpoint += '&id=' + accountId + '&TemplateId=' + templateId + '&defaultPDF=1' + '&DS7=12' + '&APIMODE=1';
System.debug('endpoint: ' + endpoint);
Http http = new Http();
HttpRequest request = new HttpRequest();       
request.setTimeout(120000);    // conga recommends setting a long timeout for generation
request.setHeader('Authorization',  'Bearer ' + sessionId);
HttpResponse response = http.send(request);
System.debug(response + '     ' + response.getBody());

Using APIMode=1 the document is attached to the record, the response body should look as follows with a debug: System.HttpResponse[Status=OK, StatusCode=200] <123exampleSFid> you can then use the given ID to find the file in your org!

You can reference the conga documentation for different API modes available, we ended up going with the email as well (mode 12): https://documentation.conga.com/composer/latest/how-to-call-conga-composer-from-apex-143199130.html

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.