function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Raj01Raj01 

Need Solution approach to invoke an external system


Hi,

I would like to the pass the account information to external system whenever user insert/Update Account record in salesforce but the issue is i can't override New/Edit buttons because Account object is using other applications with different record types.

Please find the my design analysis
1)   Create "Sync Account" Java Script detail page button to Sync account data with external systems.  
            Issues     
              i) May user get an error while clicking "Syn Account" button from external system but Account data is already saved in salesforce.
              ii) User need to click button multiple times, to save Account record in salesforce and to sync account data with external system.
             iii)  May user forgot to click on Sync account button hence data is not sync with external system. 
2)   Creating an inline Vf page and invoking an external system on page load               
           Issues       
             i)   I think salesforce is not recommending this approach. 
3)  Invoking the external system using trigger handler class based on the record typeIssues:
        Issues            
            i)   Need to do check can we show the error messages on standard detail page from apex class. 
4)  Create a new Vf page to select the record type. Based on the selection of record type navigate to standard page or vf page.For current application navigate to new vf page which need to be created to invok an external system.
For other applications navigate to Standard detail page.
        Issues:
              i)    Development effort will increase because we need to create two vf pages. One for Selection of record type and next for invoking an                       external application to send account data.
              ii)    Existing validation rules should implement using flow or apex class.

Please let me know is there any other best possible solution. 
Thanks for your help in advance.
jigarshahjigarshah
Mahi,

I believe what you are trying to accomplish is a data sync between Salesforce and the external system in consideration. Do you have the flexibility of having a near real time synchronisation of data between the 2 systems or is it expected to be in real time? Do you have the flexbility of creating additional custom fields?

If the answers to the above questions are YES, then I would recommend the following approach.

1. Create 2 custom fields on the Account record
    - Sync Status. A custom picklist field with the following options -
          1. Ready to Sync - Record has not been synced with the external system (Default value)
          2. Sync Success - Record sync was successful
          3. Sync Failed - Record sync failed
    - Error Details - A text area which capture the detail of the error occurred. You could use Field History Tracking to track updates on the same field in case of multiple subsequent errors if required.

2. Create a Scheduled Job that runs at a specific interval, lets say every 10 mins. to identify all the Account records with the "Ready to Sync" status and processes them by sending their Ids to a Batch Job which could perform callouts to send the data to the external system. 

3.  On completion of processing, the Batch Job marks the respective records as either "Sync Success" or "Sync Error" and stamps the respective error details along with.

Advantages
1. Automated sync and no manual sync effort required by the user.
2. Asynchronous and supports syncing of bulk records
3. Capability to track sync failures and resubmitting them by updating the status to Ready to Sync on the respective record.

Limitations
1. Near real time hence the external system may experience a slight delay before the new record is made available.
2. Sync failure addressal is manual

Please DO NOT forget to mark this thread as SOLVED if this ANSWER helps resolve your issue. 
Raj01Raj01
Hi jigarshah, 
Thanks for you reply,

I am looking for real time integration the reason, If record is sucessfully created in external system i would like to save in salesforce otherwise it should throw an error.
 
jigarshahjigarshah
Mahi,

In that case, I believe we can tweak the approach a little bit with some additional steps to make this more real time requirement.

1. Create 2 custom fields on the Account record
    - Sync Status. A custom picklist field with the following options -
          1. Ready to Sync - Record has not been synced with the external system (Default value)
          2. Sync Success - Record sync was successful
          3. Sync Failed - Record sync failed
    - Error Details - A text area which capture the detail of the error occurred. You could use Field History Tracking to track updates on the same field in case of multiple subsequent errors if required.

2. Write an (after insert) Apex Trigger on Account. The Apex Trigger would execute whenever an Account record with the Sync Status as "Ready to Sync" is created.

3. The Apex Trigger invokes a Batch Apex Job to perform a callout to the external system and POST the Account data and retrieve the response. The Batch Job is required since performing callouts from within an Apex Trigger is not supported. Additionally you need to check for the following things while invoking a Batch Jobs from within Apex triggers.

Only 5 concurrently executing Batch Jobs are permitted hence you need to ensure the code, verified for the available Batch Job slots and then initiate a Batch Job only. In case, the slot is unavailable immediately, you could leverage the Flex Queue or implement a custom queueing mechanism to hold the invocation templporarily and process the reuest when the slots are available. 

4. In the finish() method of the Batch Job, you can update the Sync Status on the respective Account record to Success or Failed depending upn the response recieved from the external system.

Please DO NOT forget to mark this thread as SOLVED if this ANSWER helps resolve your issue.