• #19862
    Salesforce | Manpreet Manpreet #17

    Unit testing code which has logic around the CreatedDate in Salesforce

    Unit testing code which has logic around the CreatedDate

    Tagged: , , , , , ,

    Salesforce | Suraj Suraj #121

    Hi Manpreet,

    You can create sObjects in memory with arbitrary CreatedDate values by using JSON.deserialize. This doesn’t enforce the normal read-only field attributes that prevent you from setting a createdDate value. However you can’t commit arbitrary CreatedDate values to the database (or else it would be a serious security issue).

    An example of doing so :

    String caseJSON = ‘{“attributes”:{“type”:”Case”,”url”:”/services/data/v25.0/sobjects/Case/500E0000002nH2fIAE”},


    Case c = (Case) JSON.deserialize(caseJSON, Case.class );

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?