Quantcast
Channel: Veon Consulting
Viewing all articles
Browse latest Browse all 166

Create Order from Opportunity in Salesforce using lightning component

$
0
0

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. 

SAP salesforce integration services banner

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

Creating Lightning Component in Salesforce

  • I’m creating the Lightning component with the name ‘CreateOrder’.

Creating New Lightning Bundle in Salesforce IDE

  • 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.
Copy to Clipboard
  • In the above screenshot, we are calling ‘init’ javascript function. This function is written in the controller. It will call the method ‘createOrder’ method in ‘OpportunityOder’ class. ‘init’ functions is shown in the below screenshot
Copy to Clipboard
  • 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

Copy to Clipboard
  • 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

Navigating to opportunities edit page layout

  • 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.

Creating Order in Lightning App Builder

  • Drag and drop the Component in the position you wanted to see. I have placed it above the ‘Related’ section.

Dragging component in Lightning page layout

  • 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. 

Assign opportunity page layout to default org

  • 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.

Assigning opportunity page layout to Desktop application

  • Now, you will be navigated to the ‘Review Assignment’ page where you can see where this button will be displayed. It’s shown below

Reviewing assignment in Lightning page layout

  • Now click on save. The ‘Create Order’ button is added to the Opportunity page layout. It can be seen in the below screen.

Creating Order in opportunity object in Salesforce

  • 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

Order in created an opportunity record view

  • 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.

Order from Opportunity with the line items

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.

Contact us for a free assessment

The post Create Order from Opportunity in Salesforce using lightning component first appeared on Veon Consulting.


Viewing all articles
Browse latest Browse all 166

Trending Articles