• Michael Markham
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

We are buiding a system that will automatically provision License Seats when a customer purchases our product from our custom store front. All of this logic is in Apex and we are trying to write tests to ensure this works correclty but it seems this may not be possible.

 

In its simplest form the test would pefrom the following:

- Create a License

- Update the Seats__c field on the license

- Assert Seat__c field was updated correctly

 

Seem simple but it doesn not appear to work as this is the error received when trying to accomplish this: 

Update failed. First exception on row 0 with id a07e0000000ySK2AAM; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Argument 1 cannot be null: []

 

Below is the code to reproduce:

 

//Create account license can be attached to
Account acct = new Account(Name = 'test');
insert acct;

//Create package
sfLma__Package__c pack = new sfLma__Package__c(
	Name = 'test',
	sfLma__Developer_Name__c = 'test',
	sfLma__Developer_Org_ID__c = 'abc',
	sfLma__Latest_Version__c = '3',
	sfLma__Lead_Manager__c = UserInfo.getUserId(),
	sfLma__Package_ID__c = '3',
	sfLma__Release_Date__c = system.today().addDays(-30)
);
insert pack;

//Create a package version
sfLma__Package_Version__c packVersion = new sfLma__Package_Version__c(
	Name = 'test',
	sfLma__Package__c = pack.id,
	sfLma__Is_Beta__c = false,
	sfLma__Release_Date__c = system.today(),
	sfLma__Sequence__c = 1,
	sfLma__Version__c = '3',
	sfLma__Version_ID__c = '3'
);
insert packVersion;

//Ceate a license record
Id recordTypeId = [select Id from RecordType where Name = 'Active' and SobjectType = 'sfLma__License__c'].Id;
sfLma__License__c lic = new sfLma__License__c(
    RecordTypeId = recordTypeId,
    sfLma__Status__c = 'Active',
    sfLma__Seats__c = 1,
    sfLma__License_Type__c = 'Editable',
    sfLma__Account__c = acct.Id,
    sfLma__Expiration__c = system.today().addDays(365),
    sfLma__Install_Date__c = system.today(),
    sfLma__Package_Version__c = packVersion.Id
);
insert lic;

//Update the Seats field on the license
lic.sfLma__Seats__c = 5;

//UPDATE FAILS
update lic;

 

Any ideas?

 

Thanks,

Jason

  • September 16, 2013
  • Like
  • 0