Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

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:

share|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 .

share|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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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