When a customer approves the Opportunity, a new order needs to be created in Salesforce by the sales representative. Creating an order with the same data is manual work and it takes time and effort. Now, we are automating this process with the help of a button in Opportunity. Get to know how we automated SAP Salesforce integration.
In this article, we are going to see how to achieve this in Salesforce.
Our requirement is to create an Order from the Opportunity with the line items added in opportunity and mark this Opportunity as ‘fulfilled’. To implement this, we will be creating a button in Salesforce which on click creates an Order for the Opportunity with the line items in opportunity line items and marks the Opportunity as fulfilled.
This can be implemented with the help of lightning components and a class. We will be calling the method from the lightning component with the help of a button. Let’s see it in detail
Steps to create the component :
- Create a lightning component to display the Create Order button
- Create a class to create order and order line items
- Add the component to Opportunity Page
Create a lightning component to display the Create Order button
First, we will be creating a lightning component to display the ‘Create Order’ button on the Opportunity Page.
Steps to create the ‘Create Order’ button:
- Open developer console navigate to file -> New -> Lightning Component
- I’m creating the Lightning component with the name ‘CreateOrder’.
- Below is the code to display the button. If the Order is created for Opportunity the button will be disabled. Otherwise, the button will be enabled. In the controller we are calling the class ‘OpportunityOrder’. It contains the code create Order and Order line items.
- In the above screenshot, we are calling the ‘createOrder’ method which creates the Order and Order line items.
Create a class to create order and order line items
The class contains a method named ‘createOrder’. It will take the current Opportunity information and create an ‘Order’ with those details. Below is the code for the same
- In the above method, we are inserting Order and Order line items. We are also updating a checkbox ‘Order_Created__c’= true in Opportunity which represents that the Order is created for Opportunity. We have updated the Opportunity stage to ‘FulFilled’.
Add the component to Opportunity Page
Now, we have to add the component to the Opportunity Page layout. It can be done as shown below:
- Navigate to Opportunities and open an Opportunity.
- Click on the setting Icon and select ‘Edit Page’ as shown below
- The below page will be shown where you can find the component you have created. Search for the ‘custom’ in the left-hand side component field. Below screen will be shown, where you will find the list of components you have created.
- Drag and drop the Component in the position you wanted to see. I have placed it above the ‘Related’ section.
- Now, click on Activate. Below screen will be shown. In the below screenshot you can see, ‘Assign as Org Default’. Click on this button so that it will be assigned as Organization wide Default.
- Now select the pages for which you want it to be visible and click on ‘Next’. Here I’m selecting ‘Desktop’. It is shown below.
- Now, you will be navigated to the ‘Review Assignment’ page where you can see where this button will be displayed. It’s shown below
- Now click on save. The ‘Create Order’ button is added to the Opportunity page layout. It can be seen in the below screen.
- In the above screenshot, the ‘Create Order’ button is added to the layout. The Opportunity stage is ‘Negotiation’ and there are no Orders related to this Opportunity.
- When I click on the ‘Create Order’ button, an order will be created with the information related to this Opportunity. The Opportunity stage will be set as ‘Fulfilled’. It can be seen in the below screenshot
- Once the Order is created the ‘Create Order’ button will be disabled. It can be seen in the above screenshot
- Now, navigate to Order and we can see that a new Order is created with a line item as shown below.
In this way, we can automate the process of creating an Order from Opportunity with the line items added in the Opportunity.
How we can help
Our team can help you customize and integrated Salesforce as per your business process. Read about our Salesforce Integration Services. Reach out to us for a free assessment of your business needs.