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.
-
1Have you looked at Conga Conductor? I've not used it but came across it recently: congamerge.com/products/composer/add-ons– GirbotMar 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....– Artur KępczyńskiMar 10, 2016 at 19:48
-
5(1) did you see success.salesforce.com/… ?; (2) Conga has superb support, have you asked them?– cropredyMar 10, 2016 at 20:08
-
4Artur -- 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.– cropredyMar 13, 2016 at 19:00
-
1I 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– RaoMar 16, 2016 at 18:55
3 Answers
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. 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
-
If you search our support site, we do have an article to call Composer with Apex: support.getconga.com/Conga_Composer/Advanced_Composer/… Feb 17, 2017 at 19:13
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.setMethod('GET');
request.setTimeout(120000); // conga recommends setting a long timeout for generation
request.setEndpoint(endpoint);
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