0

I have Objects DealSheet__c and Change_Log__c . when I am updating DealSheet__c record then one new record will be create in Change_log__c with the same name....

now my requirement is Suppose i am updating 3 times in the dealsheet then that updated 3rd record only need to display in change_Log__c record how could i do? Thankss in advance..

My trigger Handler Codde is


public class DatasheetHistoryClass{

    public static void datasheetHistory(Listnewlist,List oldlist){

    list HistoryData= new List();

    For(Dealsheet__c deal : newlist){

    Change_Log__c hobject = new Change_Log__c();
     string s = '.';

        hobject.name =  deal.name ;

        //hobject.isMostRecent__c= true;   
        hobject.Amended_Version__c = deal.Amended_Version__c;
        hobject.Meter_Name__c= deal.Meter_Name__c;
        hobject.Amended_Verssion_Sent_To_CP__c=deal.Amended__c;
        hobject.Amended_Versions__c=deal.Amended_Version__c;
        hobject.Broker__c=deal.Broker__c;
       // hobject.Broker_s_Name__c=  deal.Broker_s_Name__c;
        hobject.Brokerage_Per_MMBTU__c=deal.Brokerage_Per_MMBTU__c;
        hobject.BU_Contract__c=deal.Focus_ID__c;
        hobject.Buy_Sell__c=deal.Buy_Sell__c;
        hobject.Confirmation_Email_Sent__c=deal.Confirmation_Email_Send__c;
        hobject.Counter_Party__c=deal.CounterParty_Name__c;
        hobject.CP_Address__c=deal.CP_Address__c;
        hobject.CP_Address_Line1__c=deal.CP_AddressLine1__c;
        hobject.CP_Address_Line2__c=deal.CP_Address_Line2__c;
        hobject.CP_Confirm_Email__c=deal.CP_Confirm_Email__c;
        hobject.Price__c= deal.Price__c;
        hobject.Fixed_Price__c=deal.Fixed_Price__c;
        hobject.CP_ZIP_Code__c=deal.CP_P_O_CODE__c;
        hobject.Create_Date__c=deal.Create_Date__c;
        hobject.End_Date__c=deal.End_Date__c;
        hobject.External_Comments__c=deal.Trader_Comments__c;
        hobject.Instrument__c=deal.Instrument__c;
        hobject.Internal_Comments__c=deal.Internal_comment__c;
        hobject.Internal_Trader__c=deal.Internal_Trader__c;
        hobject.Link_ID__c=deal.Link_ID__c;
        hobject.Price_Type__c=deal.Price_Type__c;
        hobject.PriceIndex__c=deal.PriceIndex__c;
        hobject.ReSend_Email__c=deal.ReSend_Email__c;
        hobject.Start_Date__c=deal.Start_Date__c;
        hobject.Strategy__c=deal.Strategy__c;
        hobject.Terms_Condition__c=deal.Terms_Condition__c;
        hobject.Total_Volume__c=deal.Total_Volume__c;
        hobject.Trade_Date__c=deal.Trade_Date__c;
        hobject.Tradebook__c=deal.Tradebook__c;
        hobject.Vlm_Day__c=deal.Vlm_Day__c;
        hobject.Tradebook__c=deal.Tradebook__c;
        hobject.NG_Pipe_Name__c=deal.NG_Pipe_Name__c;

        HistoryData.add(hobject);

}



    try{
 insert HistoryData;
   }

   catch(Exception e){


   } 

    }

} 

5
  • I would think you need additional requirements. Is there some window in which the 3 updates can occur? Does it occur all within the same code invocation? Is it just remaining on the same page?
    – willard
    Commented May 23, 2016 at 13:59
  • how are you updating three times? Is it through workflow field update/updating field through trigger or user changes three times? Commented May 23, 2016 at 13:59
  • Ya 3 updates will done in same window of DealSheet..and those 3 records are ddisplaying in Change_Log__c object....but in change_Log__c Object i want to show only 3 record
    – srihari
    Commented May 23, 2016 at 14:13
  • In the edit page only I am updating 3 times...when i am updating then trigger fires and new record will create in Change_Log__c Object
    – srihari
    Commented May 23, 2016 at 14:14
  • User Changes 3 times
    – srihari
    Commented May 23, 2016 at 14:41

1 Answer 1

1

Each DML event on DealSheet__c will invoke a trigger. If that trigger then writes a record to ChangeLog__c, you will get multiple records for each user transaction that causes the DML. This is expected SFDC behavior.

Since you are doing the change log in a trigger, you don't really know when the user is done editing (drafts) from finalizing (publish).

Strategies for dealing with this are hard and won't be bullet proof. For example, you can post-process the changelogs and merge them together if they were created in the same session id for the same deal sheet id. This could be done via nightly job considered only ChangeLogs created more than 24 hours ago.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .