function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sunny_SlpSunny_Slp 

Custom field history tracking

Hey everyone,

 

We're trying to track 20+ fields on one custom object (Candidate__c), and since SFDC only allows for 20, I though of having a trigger on that custom object that gets triggered for insert,update. The plan was then to go ahead and

 

create a  Candidate_History record with parentId=Candiaterecord.Id, Field=Field22,NewValue=Trigger.new[0].Field22,OldValue=Trigger.old[0].Field22; and then insert it?

 

the webAPI document says History objects of custom objects support create(), I assumed it would mean we can create and insert the object?

 

Here is a scaled down example of what I'm trying to do, is this even possible? I'm getting some wierd DML exceptions with no error message to know what exactly happend.

 

trigger candidateAudit on Candidate__c (after insert, after update) {
      Candidate__c currentobject=Trigger.new[0];                                                                       Candidate__History historyrecord=new Candidate__History(parentId=currentobject.Id);
insert historyrecord;
}



Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I don't think this is possible, unfortunately.  When I check the accessibility of my <custom_object>__History types in the Force.com IDE schema explorer, I don't see createable - only queryable, retrievable and replicatable.

All Answers

bob_buzzardbob_buzzard

I don't think this is possible, unfortunately.  When I check the accessibility of my <custom_object>__History types in the Force.com IDE schema explorer, I don't see createable - only queryable, retrievable and replicatable.

This was selected as the best answer
Sunny_SlpSunny_Slp

I was afraid someone would say that. Looks like I would have to have a custom object that would act as a History object and then insert records of that object.

 

Thanks for clarifying.

bob_buzzardbob_buzzard

That's the exact route we've had to go in the past.