I have some logic where I have to send emails about Opportunities that have certain OpportunityHistory objects at certain date times.

I would like to test this but it means I need to be able to explicitly set SystemModstamp in my test. When I try to do this, I get:

save error: Field is not writeable: OpportunityHistory.SystemModstamp

Is there anyway around this?


SystemModstamp is an Audit field and is not set-able even if you get Salesforce to allow you to access Audit fields.

See here for more info:


|improve this answer|||||

The systemModified time stamps are not allowed to overwrite .Those are not writable field .Testing may require with reducing the value for testing for small interval.

Example if your test scenario is with 30 days old change in code for 2 days old date and test it and after test update again in code for 30 days old .

|improve this answer|||||

What is the logic that references OpportunityHistory?

OpportunityHistory is read only and is system generated based on criteria so you cannot create it in tests nor can you update an opportunity in your tests then reference the history as the records are only created upon a database commit.

I've ran into this issue before using ActivityHistory and had to query tasks instead of history to make it work - this may be more difficult with opportunity history.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.