You need to sign in to do that
Don't have an account?
Can't write Apex tests against the LMA
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
Hello Jason,
The error 'FIELD_CUSTOM_VALIDATION_EXCEPTION' occurs when there is a validation rule and one of the tests running on org is not conforming to it.
Possible resolutions are to either modify the test or disable the validation rule temporarily.
That is not what is happening in this case, there are no validation rules. That type of error, 'FIELD_CUSTOM_VALIDATION_EXCEPTION', can also be displayed with the Apex .addError() method. The error message itself "Argument 1 cannot be null: []" is also a system generated message that happens when you call an Apex method with the incorrect arguments defined.
This is most likey waht is happening inside the LMA:
Something like that would also cause the error message I am seeing to be displayed.
Really, I just need some internal expertise and guidance on how to write Apex tests for updating the Seats__c field on a License record.
Did you ever make any progress on this? I'm in the same boat now, trying to accomplish exactly what you were, and getting exactly the same result.
thanks in advance
brenda
https://success.salesforce.com/issues_view?id=a1p300000008XTRAA2
Mike
Our situation is somewhat unique in that we simply needed to get the required code coverage for our trigger on the sfLma_License__c object. We did not need a functional unit test at this point. So this may not be of help if you HAVE to do verification of the functionality. This is what we did.
As we could not create an instance of the sflMa Package in Production and did not want to roll back to previous version (1.15), we simply retrieve all existing licenses and call update on the first one returned, which ensures that our trigger for the License is executed and we have our code coverage. Here is the code for getting all the licenses
List<sfLma__License__c> lstLicenses = [select Id, sfLma__Lead__c, sfLma__Package_Version__c FROM sfLma__License__c
where sfLma__License_Type__c='Editable'];
if (!lstLicenses.isEmpty()) {
// Add your functionality here for each license you find. For us, invoking update fires our trigger
update lstLicenses.get(0);
}
Hope this helps!
Brenda
Mike