Category Archives: Force.com Platform

Integration via Outbound Messages-SF API Call Manager

This article is for exploring integration possibilities via outbound messages and solving below problems:

  1. Timeout issue – In salesforce there is strict limit of 120 seconds for callout. This could be solved if API calls are carried outside of salesforce like in heroku app where no such limit for callout is there.
  2. API Calls which requires polling – Polling for response becomes difficult in salesforce as in order poll for result batch is required which runs at regular interval but there cannot be more than 5 batches running simultaneously. This can be solved by implementing polling logic in heroku app where threading could be used for polling and making inbound call to salesforce when results are available.

This idea came up when I was having discussion with my colleague Tushar Kaore on integration approaches. We thought that lets try to analyze the performance and reliability of outbound messages in integration.

Here is the design of this framework:

OutboundMessagesIntegration

Integration via Outbound Messages

Lets see how this would work

  1. Whenever API Call has to be made then in salesforce API Call record has to be created which would include below details
    • Endpoint
    • Request
    • Headers
  2. On create of such API Call records salesforce would initiate an outbound message call to the heroku application with all the details which would be required to make API call
  3. Actual API Call will be made by heroku app to the external system. Here an API call which takes more than 120 seconds can be made and it is required to do polling then heroku app can handle that by polling in regular intervals of time.
  4. Heroku app will receive the response.
  5. Inbound API call would be made to salesforce to pass on the response received by heroku app.
  6. Response would be updated in API Call record and on trigger of API Call record response could be processed and proper actions could be taken.

In this structure two applications are involved Salesforce App and Heroku app.

Steps to configure app:

  1. Heroku App: Install the Heroku App  : heroku-api-call by using deploy to heroku button from repository home page.
  2. Salesforce App: Insall the Salesforce App : sf-api-call by using Deploy to Salesforce button from repository home page.
  3. Configure workflow rule: Create workflow rule on API Call object with the outbound message action as per below screenshot.

    sf-api-call

    Outbound Message Action

  4. Add Remote Site setting: Add the remote configured endpoint as remote site setting.

How to test:

Create an API Call record in salesforce with the endpoint. As soon as the record gets created salesforce will make outbound message call to heroku app. Heroku app will make API call to the endpoint and it will be update the received response to salesforce via making inbound api call.

I will be be testing this for performance and will check its reliability to use in production applications. Currently only GET API calls are supported and will update the code to have below featues:

  1. Headers support
  2. POST call support

features list will go on…..

Whenever real time integration is not required and this approach could be used to solve issues of

  1. Callouts taking more than 120 seconds
  2. Whenever polling for response is required.

Result of this exercise:

I created nearly 50K API calls (thats lots of API calls) and tried to see how many API calls will get processed by this mechanism. Results are very promising

APIPerformanceReport

Results shows that 20K API calls are fulfilled within 3 minutes i.e. 113 fulfilled API call/second. My heroku instance was bombarded with outbound messages calls and now it is down.. 🙂

Note these are the results with free heroku instance with one dyano only. So imagine if you have a heroku app with good number of dynos to fulfill requrest then you can think of very promising results.

API Call is made to http://headers.jsontest.com/ for testing.

Happy learning and keep exploring..

 

Advertisements

User Creation in Salesforce

This post is for the best practices to be kept in mind while loading users in the system. If client business users starts getting notification when they are not supposed to then that could create chaos. Below are the points which needs to be considered while loading users in the system.

  1. User Template: User data should be gathered before hand, to make sure that we are not missing any information which we are supposed to be asked to client. Template should be used so that no data would be missed. Attached is the user template using which we could ask client to provide all user details UsersTemplate.
  2. SSO consideration: If the salesforce org is using SSO then federation id should be asked before hand and should be part of user template.
  3. Multicurrency: If salesforce org uses multicurrency then it would be good to include that CurrencyIsoCode column in the user template.
  4. External Id: No matter how much you plan but you could have some wrong data like incorrect firstname, lastname etc. It would be a good practice to create external id in user object so that users could be upserted and data could be corrected.
  5. Email Id change: Whenever user’s email ids are changed then users gets notification for confirming the email address and also notification is sent to the email id which you are changing. If you want to change the email ids without any notification to users then you can turn of the Email Deliverability to “No Access”. This will make sure that email id is changed without creating any chaos of notifications.
  6. Reset Password: Whenver user loading process is going on it would be good to turn off Email Deliverability. When you think that now its the time to welcome users then you can reset the password. Users will get the email to set their passwords.
  7. Feature Licenses: If you want to activate some feature licenses then that could be added as a part of user template.

    FeatureLicenses

    Feature Licenses

  8. Welcome Email: If you want to send welcome emails to user for helping with the documents to understand salesforce and with next steps. To implement this you would need to create email template and which would be used by workflow rule on user object.

Above list could act as a checklist for your plan of creating users in salesforce.

Notifications for Scheduler if they don’t run.

Hi all, We use schedulers and batches in salesforce for many reasons like daily cleanup, daily processing of data and there comes the need of checking that if your scheduler is running properly with the specified time interval. Here is the solution to get the notification if your scheduler did not run within a particular interval. You will get a nice email alert if the scheduler is not running.

Follow the following steps.

1. Create one object Notification with name as text field and a checkbox as notify (Notify__c).

2. Create the “Notify_after_one_hour__c” datetime field in the notification object.

3. Create the following method in your Notification class.

4. Create the workflow rule as follows

notification_workflow

This workflow rule adds an action to send the email after one hour of the “Notify_after_one_hour__c” date time field from the notification object. Here just call the method from the notification method and specify the greater time interval in minutes than the duration between two consecutive executions of scheduler. Call this Notification.addNotificationFor(‘<JobName>’,<duration in minutes>). Let’s say there is a scheduler which runs at the interval of two hours and you want to get notified it the scheduler did not run after 2 hours. Then just add this line to the start of the schduler as

Notification.addNotificationFor(‘SchedulerRunningAfterEvery2Hours’,130);

Here I have set time as 130 minutes. Here first time when this method gets executed it will add an action to send email after 2hours and 10 minutes. If the scheduler runs properly after 2 hour then this method will get again executed and the time dependent action will get recalculated and email notification will be forwarded ahead by 2 hours and suppose if scheduler did not run after 2 hours then email notification will not get again forwarded and you will get email notification after 2hours and 10 minutes.

This can be used in schedulers, regularly running jobs.

I hope this will help to get notified if your important job is not running after specified time interval.