Skip to content

Instantly share code, notes, and snippets.

@afawcett
Created April 21, 2014 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afawcett/11156378 to your computer and use it in GitHub Desktop.
Save afawcett/11156378 to your computer and use it in GitHub Desktop.
Attempt to create Standard Pricebook2 via JSON deserialize... fail sadly...
@IsTest
private with sharing class TestPricebook {
@IsTest private static void testPricebook()
{
System.assertEquals(0, [select Id from Pricebook2 where IsStandard = true].size());
Pricebook2 pb = (Pricebook2) JSON.deserialize('{"Name":"Standard", "IsStandard":"true"}', Pricebook2.class);
System.assertEquals(true, pb.IsStandard);
insert pb;
System.assertEquals(1, [select Id from Pricebook2 where IsStandard = true].size());
}
}
@alan-morey
Copy link

Haha, I was thinking about trying that out, just didn't get around to it. At least now I know, pity though, it would have been sweet to be able to write tests without SeeAllData on.

I've used JSON deserialize for writing to CreatedDate and and LastModifiedDate fields and it works a treat. I was wondering if it would work for formula fields too, have you tried this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment