Using the native quote object in Salesforce extends functionality of quoting. This allows users to send pdfs of quotes, as well as keep a versioned storage of all quotes sent to customers. Although quotes are linked to opportunities, many of the intuitive features are missing, including custom fields on quote line items syncing with custom fields on opportunity products.
Prerequisites
- Quotes Enabled
- Expose the Opportunity Line Item Id in a formula
- Enterprise Edition
Enable Quotes
To enable quotes in an org:
- Go to setup
- Search
Quotes
and go toQuote Settings
- Click
Enable
Create Opportunity Line Item Id Formula
To expose the Opportunity Line Item ID on the Quote Line Item:
- Go to setup
- Go to the
Object Manager
- Find the
Quote Line Item
- Go to
Fields & Relationships
and create a new field
The field should have the following properties: Type: Formula Label: Opportunity Line Item Id Name: Opportunity_Line_Item_Id__c Return Type: Text Formula: CASESAFEID(OpportunityLineItem.Id)
Creating Custom Fields
Once we've set up the basic Salesforce configuration, we can move on to creating custom fields for the data we want to link. This works for any writable field types, but for this example I will use a date field, called Shipment_Date__c
These custom fields need to be created on both the Quote Line Items and the Opportunity Products
Writing an Apex Trigger
Now that we've set up the necessary configuration in Salesforce and created our custom fields, we can write an Apex trigger to link the data between the quote line item and opportunity products. In your preferred editor, create an Apex trigger named QuoteLineItemTrigger
for the quote line item object. In the trigger context, use "after insert" and "after update" to send DML.
We use a Trigger Handler system for better code architecture, so create the Apex class QuoteLineItemTriggerHandler
Any additional fields you want to link within this system will be inserted in the Map Fields
section. Just replace shipment_date__c
with the API name of your field.
Conclusion
Implementing the trigger framework above will help you link Salesforce data between Quote Line Items and Opportunity Products. If you want a visual walkthrough, check the video here:
If you are interested in how G2 Technologies can support your Salesforce needs, get in touch: https://g2technologies.com/pages/contact