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.
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.
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.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