Activity › Forums › Salesforce® Discussions › Is there any Standard feature to track Opportunity Line Item in Salesforce?
-
Is there any Standard feature to track Opportunity Line Item in Salesforce?
Posted by Suraj on April 19, 2017 at 2:15 PMIs there any Standard way to track OpportunityLineItem in Salesforce?
Saurabh replied 9 years ago 2 Members · 1 Reply -
1 Reply
-
Hi Suraj
Salesforce does not provide any standard feature for history tracking on opportunity line items but by using custom object and trigger we can get to this solution
First you need to create custom object as i created opportunity_Tracking__c
trigger opportunitytracking on OpportunityLineItem(After insert, After update) {
List<opportunity_Tracking__c> hisTrackList = new List<opportunity_Tracking__c>();
//
// Iterate through the OpportunityLineItems and create the History Tracking Record.
//
for (Integer i=0; i < Trigger.new.size(); i++) {OpportunityLineItems newCM = Trigger.new[i];
if(Trigger.isInsert) {
hisTrackList.add(new opportunity_Tracking__c(OpportunityLineItem_Record_Id__c = newCM.Id,
Object_Name__c = ‘OpportunityLineItem’,
Field_Name__c = ‘Status’,
Previous_Value__c = ”,
Current_Value__c = newCM.Status,
Modified_Date_Time__c = System.now(),
Modified_By__c = UserInfo.getUserId()
));
} else if(Trigger.old[i].Status != newCM.Status){
OpportunityLineItem oldCM = Trigger.old[i];
hisTrackList.add(new opportunity_Tracking__c(OpportunityLineItem_Record_Id__c = newCM.Id,
Object_Name__c = ‘OpportunityLineItem’,
Field_Name__c = ‘Status’,
Previous_Value__c = oldCM.Status,
Current_Value__c = newCM.Status,
Modified_Date_Time__c = System.now(),
Modified_By__c = UserInfo.getUserId()
));
}
}
if(!hisTrackList.isEmpty()) {
insert hisTrackList;
}
}Hope it may help you:
Log In to reply.