We’re Here to Help!!

Find A Solution, Learn Best Practices & Get Support 24x7

Invoking an external URL or event from Flosum

Follow

Sometimes it might be necessary to trigger an external URL or event in another system when some event happens in Flosum. eg when a patch is deployed, we might want to automatically run the QA test cases associated with the components in the patch. 

Since Flosum is natively built on Salesforce platform, it can utilize the powerful API and patterns available from Salesforce to integrate with external software systems. 

Please find below sample code for triggering external events from Flosum. In this example, a trigger is sent to an external website. The trigger is sent after the deployment of a patch completes.

Sample Code 1:
This code fires when the deployment completes. It gets the Deployment ID and passes that to the method to call the webservice.


trigger PatchApplicationTrigger on Flosum__Patch_Application__c (after insert) {
List<String> listId = new List<String>();
for (Flosum__Patch_Application__c oneDeployments : Trigger.new) {
listId.add(oneDeployments.Id);
}
ExternalCallout.futureExternalService(listId);
}

 

Sample Code 2:
This method actually calls an external website (mentioned below) to pass the Deployment ID.

public with sharing class ExternalCallout {
public static String getInfoFromExternalService(List<String> listId) {
String result = '[]';
HttpRequest request = new HttpRequest();
String strParam = EncodingUtil.urlEncode('Following patch id was deployed:', 'UTF-8');
request.setEndpoint('http://saloforce.com/cgi-bin/calloutservice.cgi?debug=' + strParam + listId.get(0));
request.setTimeout(3000);
request.setMethod('GET');
try {
Http http = new Http();
HttpResponse httpResponse = http.send(request);
System.debug('>>>>>>>>>>>>>>>>>>>>>>>\n\n'+httpResponse.getStatusCode());
result = httpResponse.getBody();
System.debug('>>>>>>>>>>>>>>>>>>>>>>>\n\n !'+httpResponse.getBody()+'!');
result = '';
if (httpResponse.getStatusCode() == 200) {
if (httpResponse.getBody().trim().toLowerCase() == 'done') {
result = 'OK';
}
}
}
catch (Exception e) {
result = '[{"STATUS_REQ":"ERROR", "ERROR_MESSAGE":"' + e.getMessage() + '", "RESPONSE":""}]';
}
System.debug('>>>>>>>>>>>>>>>>>>>>>>>result\n\n'+result);
return result;
}
@future(callout=true)
public static void futureExternalService(List<String> listId) {
String infoFromExternalService = getInfoFromExternalService(listId);
List<Flosum__Patch_Application__c> listDepl = new List<Flosum__Patch_Application__c>();
System.debug('>>>>>>>>>>>>>>>>>>>>>>> OK\n\n'+infoFromExternalService);
if (infoFromExternalService == 'OK') {
for (String idDeployments : listId) {
Flosum__Patch_Application__c tempDeployments = new Flosum__Patch_Application__c();
tempDeployments.Id = idDeployments;
tempDeployments.statusCallout__c = 'worked';
listDepl.add(tempDeployments);
}
}
else {
for (String idDeployments : listId) {
Flosum__Patch_Application__c tempDeployments = new Flosum__Patch_Application__c();
tempDeployments.Id = idDeployments;
tempDeployments.statusCallout__c = 'failed';
listDepl.add(tempDeployments);
}
}
if (listDepl.size() > 0) {
update listDepl;
}
}
}

Print Friendly and PDF
Was this article helpful?
0 out of 0 found this helpful

Comments