• #19862
    Salesforce | Manpreet Manpreet #17
    Forcetalks

    Unit testing code which has logic around the CreatedDate in Salesforce

    Unit testing code which has logic around the CreatedDate

    Tagged: , , , , , ,

    #19867
    Salesforce | Suraj Suraj #121
    Forcetalks

    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”},

    “Id”:”500E0000002nH2fIAE”,

    “CreatedDate”:”2012-10-04T17:54:26.000+0000″}’;
    Case c = (Case) JSON.deserialize(caseJSON, Case.class );
    System.debug(c.createdDate);

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

Please to reply to this topic.

CONTACT US

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

Sending

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

or    

Forgot your details?