Find your content:

Search form

You are here

Is there a way to set SystemModstamp on a newly created SObject in a unit test?

 
Share

I need to create a SObject in a unit test with the SystemModstamp set. I've been using Opportunities in my unit test, but I am not tied to that specific SObject. I also am not tied down to SystemModstamp (though that is what my app used in production). I really just need to be able to modify a DateTime field on a SObject. Ideally though, I would be able to set the SystemModstamp or cause it to be set. I tried inserting the newly created Opportunity, but it looks like that insert doesn't populate the SystemModstamp.


Attribution to: edgartheunready

Possible Suggestion/Solution #1

The SystemModStamp will always be set. If you requery the object in your test class it should get you the SystemModStamp:

Account a = new Account();
a.Name = 'name';
insert a;

system.debug(a.systemModStamp);
system.debug([select Id, SystemModStamp From Account Where Id = :a.Id]);

returned:

|DEBUG|null
|DEBUG|(Account:{SystemModstamp=2014-04-03 19:08:12, Id=001c000000Y36ucAAB})

Attribution to: Guy Clairbois

Possible Suggestion/Solution #2

this is one of the audit fields which salesforce managed internally. Yes, it is possible to update it but you have to open a case with Salesforce and they will allow you do that at your own risk.


Attribution to: Bforce
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/31778

My Block Status

My Block Content