Skip to main content

Connect MuleSoft with Salesforce and Create Record in Salesforce With MuleSoft.

 




In this blog, we are going to discuss about how we can connect MuleSoft with Salesforce Environment and creates the records on it.

pre-requisite :-

1) Anypoint platform - (https://anypoint.mulesoft.com/login/signin) -> Sign in -> Anypoint studio(Download).
2) Java 8 -> (https://www.oracle.com/in/java/technologies/javase/javase8-archive-downloads.html)
3)Salesforce environment -> (https://login.salesforce.com)

Steps :-

1) Go to AnyPoint platform -> File -> New -> Mule Project.

2) Give the mulesoft project name and click on Finish.

3)On the left hand side you can see your project under package explorer.

4)Now, you are seeing "To get started, drag an operation or scope from mule palette". Now to get started we have to pull one component from mule palette(Which is on the right hand side of the main screen) and drop into the main screen.

5)For us, you have to drag "Listner(HTTP)" component from the mule palette and drop into the main screen.

6)Now your screen will look like below screen shot.


7) Now just below the main screen, we can see the properties of "Listner(HTTP)" component.

8) Into the General property, under basic setting, you have to click on "+" icon  to integrate your mulesoft with your local host.




9) You will a new screen, there you can see "HTTP Listner config" with protocol,  host and port. This is because we are running our application in localhost. You just have to Test the connection and if the connection is successful, hit the ok button. If not, try to change the port number and do the same thing again.

10)  After that you have to give the path, which is below the basic setting. You can give any any name like this '/salesforcewallah'.

11) Now, you have to pull the any salesforce component, So for the time being I m taking create call.

12) Go to login.salesforce.com -> go to setting under avatar icon -> then click on 'Reset my security token'. This helps us to create the connection with the Mulesoft.

13) You can see you will get a mail with token and username.

14) Now in salesforce create call component, You have to go to connector configuration and  fill out the necessary details. You can refer the below screen shot for this.





15) After filling the mandatory fields, you can click on test connection. Now at this point you are connected with the salesforce.

16) So to test this, You can add one "Transform Message" component between the listner and salesforce create component. Now go to transform component properties to map the fields with salesforce object.

17) Beside payload, you can see Define metadata, you have to click on it and give the metadata type and add type id as anything.

 [{

"name":"salesforce wallah aaaaaa",
"billingCity":"London"
},
{
"name":"salesforce wallah aaaaaa",
"billingCity":"London"
},
{
"name":"salesforce wallah aaaaaa",
"billingCity":"London"

}]

18) Copy the above code and paste into the json file and select the Type as JSON and schema should be Example. Select the JSON file and it will create an json type data.See the below screenshot for your reference.


19) Now we have to write the mapping code with the salesforce object.Please refer below screenshot or your reference.


Mapping code

payload map (item, index) ->
{
"Name": item.name,
"BillingCity" : item.billingCity
}


20) Now your flow will be look like the below screenshot. Please check the below screenshot.




21) Just deploy/Run the application and see the results with the Postman. Please see the below postman response.



DEMO :- 




Comments

Popular Posts

Top 100 Most common used Apex Method in Salesforce

  Here are 100 more Apex methods in Salesforce: 1.       insert: Inserts records into the database. 2.       update: Updates records in the database. 3.       delete: Deletes records from the database. 4.       upsert: Updates or inserts records into the database. 5.       query: Retrieves records from the database using SOQL. 6.       getContent: Retrieves the content of a document or attachment. 7.       getContentAsPDF: Generates a PDF file from a Visualforce page or HTML content. 8.       addError: Adds a custom error message to a record and prevents saving. 9.       start: Initiates processing in batch Apex. 10.    execute: Processes a batch of records in batch Apex. 11.    finish: Finalizes processing in batch Apex....

How to create ICS/Calendar File | Helps you to download the calendar invites

  Want to know how to create ICS(Internet Calendar Scheduling) file for Business purpose....👀    ICS (Internet Calendar Scheduling) file is a calendar file saved in a universal calendar format used by several email and calendar programs, including Microsoft Outlook, Google Calendar, Notes and Apple Calendar. It enables users to publish and share calendar information on the web and over email. Lets see the code. The code is written in lwc(Lightning web component). HTML:   <template> <div class="login-container"> <h1 style="size: 14px;"><b>Create ICS File</b></h1> <div class="form-group"> <lightning-input type="datetime" name="input1" value={EventEndValue} onchange={startDate} label="Enter Start date/time value" ></lightning-input> </div> <div class="form-group"> <lightning-input type="...

Sharing records by Apex in Salesforce

  Greetings, everyone! In today's session, we'll delve into the topic of sharing records within an Apex class. As we're aware, there exist various methods through which we can accomplish the sharing of records. We engage in record sharing primarily when the object's Organization Wide Default (OWD) settings are set to private. Sharing settings come into play when certain predefined criteria are met, allowing us to extend access to records to designated groups or roles. In cases where intricate logic is involved, manual sharing is employed. While this approach proves beneficial for specific records, instances where a multitude of records require automated handling, Apex sharing becomes the preferred solution. Salesforce offers a 'Share' object for each type of object, with distinct naming conventions: For standard objects, it's 'StandardobjectName+Share', such as 'AccountShare' for the 'Account' object. Custom objects follow the pattern...

Login Salesforce Without Credentials(Without UserName and Password)

  Want to login into Salesforce without credentials. Please follow the below STEPS: STEPS:-  1)  Goto to setup  --> Open Developer Console. 2) Goto debug --> Open Execute Anonymous Window --> It will open the pop. 3) Please write the below code in Anonymous window.       String sessionId = UserInfo.getOrganizationId() + '' + UserInfo.getSessionId().SubString(15);      System.debug('$$$$ Session Id ' + sessionId); 4) Click on Execute and filter the debug. You can see one session Id with Organization Id. Now, we have to copy the debug session Id and create one login URL. Steps to create Login URL: 1) Copy the Salesforce URL. Please refer the screenshot shown below. 2) Now concatenate the session Id with the salesforce URL and your Session Id Will look like below. https://d5g000004zfq2eai-dev-ed.lightning.force.com/secur/frontdoor.jsp?sid=00D5g000004zfQ2EAI!AQgAQKzTcnQTifXpRnQ7DgECtk_rv.w9BT5FoPEAmoy_UrgG4HJ6B9YFpQ2LVlmnJhBrYPSf8cI...

SF Fact #03 | Undelete Failed, Entity is not in recycle bin

  Similar to ENTITY_IS_DELETED error, if we attempt to undelete a record from recycle bin by mistake which has already been hard deleted, the following error is encountered: UNDELETE_FAILED. When a record is deleted, it moves to the Recycle Bin. This is known as "soft deletion," allowing the record to be easily restored through the user interface. However, under certain conditions, a deleted record will no longer appear in the Recycle Bin: Master-Detail Relationship (Child Deleted First): If a record is a child or detail in a master-detail relationship and it is deleted before its parent record, then after the parent is deleted, the child record transitions to a "hard deleted" status. In this state, the child record cannot be recovered through the Recycle Bin and must be recreated if needed. Master-Detail Relationship (Parent Deleted): If a record is a child or detail in a master-detail relationship and the parent record is deleted, the child record is also soft del...