Sunday, September 25, 2016

Data Driven Integration Framework


Data Driven Integration Framework: Scalable, Re-usable approach for systems Integration

Scenario: On Premise Application Integration with Salesforce.com

Why?

  • Eliminate code redundancy for multiple integration syncs between systems
  • Leverage for future integration between systems
  • De-coupling the change management between systems
  • Productivity


What?
  • A Script Interpreter Framework which is used to read the integration script definitions (curl calls) stored in a data store for performing the integration calls using the real time data
How?
Use Case/Example:
Automation of syncing contact information from an “On Premise Application” to “Salesforce CRM” for a given account without leveraging any salesforce connectors/tools for Salesforce.

Flow:
When the contact sync event is triggered from the “On Premise Application” the following steps needed to be performed:
1> Find the “Account Record Id in Salesforce CRM” with the “Account Name” field in the “On Premise Application”. If not found create it.
2> Find the “Contact Record Id in Salesforce CRM” with the “Contact Email Address” field in the “On Premise Application”. If not found create it.
3> Find if the record exists in “Account Contact Role object” in Salesforce CRM. If does not exist then insert.
4> Repeat the steps (2 and 3) for “multiple contacts” sync for the given account.

What is the one of the simplest solutions can be using “Standard Salesforce Rest API”?:
1> Write 6 curl statements by sending the necessary data from the On Premise Applications.
2> Use a loop in case of multiple contacts.

Challenges with the above solution:
1> The code is not re-usable/scalable as code needs to be changed whenever field API name changes, new object integrations etc.

How “Data Driven Integration framework” can solve some of the above changes?
1> Create a XML based configuration or a data store with the following attributes:
  1. Event name
  2. Step Sequence #
  3. Step Name
  4. Dynamic Script
  5. Alternate Script
  6. Operation Type (Get/Set/Insert/Upsert/Delete)
  7. Transaction Type (single/multiple)
2> Develop a “Script Interpreter” that Reads the configuration, interprets and executes the integration calls.
In the above example the configuration will look as follows:


Friday, July 15, 2016

Select * from SOQL in Salesforce

Select * from SOQL in Salesforce

Most of us come across challenges to run "Select * from SOQL". The following visualforce code snippet will let you run "Select * from SOQL".

You can get access to this page by installing this un-managed package to your salesforce org:
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t61000000gURQ

*** Outstanding/Known Issues/Workaround:
  • Select * from SOQL works fine for custom objects or objects with fewer fields
  • You could run Select * from SOQL for any standard object and you could get list of fields and then break down the select query string and run the SOQL and then merge the result.

Tuesday, July 5, 2016

ProgressBar Component (Re-usable) -- Can be plugged into any Visualforce page or standard layout

Progress-bar Component (Re-usable) -- Can be plugged into any Visual-force page or standard layout (salesforce)

Use-case:
"Progress-bar" inform users of how close they are to completing a certain goal by showing percentages of completion along the way.

What is the Re-usable component about?
  • This re-usable visual force component (built in visualforce/apex language) allows you to map a given field in a custom object with a given value and the corresponding image via a "Custom setting".
  • This visual force component is re-usable and can be plugged into a visual force page and which can be embedded into a standard page-layout or a stand-alone visual force page.
  • Once done can be leveraged in multiple scenarios.
  • The configuration can be maintained in the "Custom setting"
How to use this component?
  • Install the "Un-managed package" in the link provided in the page (scroll down)
  • Upload images for a given progress bar in static resource and get the corresponding links by clicking on "View files" in Static resource.
  • Set-up the configuration in the "Custom Setting" (mentioned in component list below)
  • Map the Object name, field name, value and corresponding image link in the custom setting.
  • Add the component to a given visualforce page
  • Embed the page to a standard layout or use-it in the stand-alone visual force page

Example:





Component list:
Page: StageProgressBarVfPage
Component: ProgressBarComponent
Class: ProgressBarReusableCntrlTest, ProgressBarReusableCntrl
Custom Setting: ProgressBarImages__c
Static Resource: MockProgressBar

*** You can install the unpackaged components from the following link: ***
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t61000000gUPP

Code Snippet:

StageProgressBarVfPage: 

<apex:page StandardController="Opportunity" sidebar="false" showheader="false"> <c:ProgressBarComponent objName="Opportunity" field_Name="StageName" field_Value="Prospecting"/> </apex:page>

 

ProgressBarComponent:

<apex:component controller="ProgressBarReusableCntrl"> <apex:attribute assignTo="{!objectName}" name="objName" type="String" Description="Object Name" required="true"/> <apex:attribute assignTo="{!fieldName}" name="field_Name" type="String" Description="Field Name" required="true"/> <apex:attribute assignTo="{!fieldValue}" name="field_Value" type="String" Description="Field Value mapped to a given image" required="true" /> <center> <apex:outputPanel id="CentreImage"> <apex:image url="{!ProgressBarURL}" rendered="{!NOT(ISBLANK(ProgressBarURL)) && NOT(ISNULL(ProgressBarURL))}" id="StatusImage"/> <apex:outputText rendered="{!ISBLANK(ProgressBarURL) || ISNULL(ProgressBarURL)}"><b>{!$Label.Default_Image}</b></apex:outputText> </apex:outputPanel> </center> </apex:component>

ProgressBarReusableCntrl:

public class ProgressBarReusableCntrl { public String objectName{get;set;} public String fieldName{get;set;} public String fieldValue{get;set;} public ProgressBarReusableCntrl(){ } /** * @description Gets image URL from ProgressBarImages__c custom setting to display it on the component */ public String getProgressBarURL(){ String value = (fieldValue!=null && fieldValue.contains('<a href'))?fieldValue.stripHtmlTags():fieldValue; String query = 'select Field_Value__c, Image_Link__c from ProgressBarImages__c where Object__c =\'{objectName}\' and Field_Name__c =\'{fieldName}\' and (Field_Value__c =\'{value}\' or Field_Value__c = \'Default\')'; query = query.replace('{objectName}', objectName); query = query.replace('{fieldName}', fieldName); query = query.replace('{value}', value); List<ProgressBarImages__c> imageLink = Database.query(query); String image = null; for(ProgressBarImages__c link: imageLink){ if(link.Field_Value__c != 'Default' || image == null){ image = link.Image_Link__c; } } return image; } }