+ Start a Discussion
Andy Freeston_LarterAndy Freeston_Larter 

Testing LMA License Activation

Hi. I am in the process of providing some automation for my sales teams LMO. My code is trying to set the status of a license to Active and this is failing with a validation error. The code is running in a test org. The licence, package version, and package have been created in a test method.


Have I missed some vital data from one of the LMA objects or is there some magic to changing the license status?


This error is raised on the update of the license:

20:49:10.362 (362243000)|EXCEPTION_THROWN|[39]|System.DmlException: Update failed. First exception on row 0 with id a06D000000PVrETIA1; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Argument 1 cannot be null: []


The test code is:

sfLma__Package__c pkg = new sfLma__Package__c(
	Name = 'Licence Testing',
	sfLma__Release_Date__c = Date.parse('01/01/2010'),
	sfLma__Package_ID__c = '033A00000000000IAA' );
insert pkg;

sfLma__Package_Version__c pkgVer = new sfLma__Package_Version__c(
	Name = 'Licence Testing Jan 2010',
	sfLma__Version__c = 'Jan-10',
	sfLma__Version_ID__c = '04tA00000000000IAA',
	sfLma__Package__c = pkg.Id,
	sfLma__Release_Date__c = Date.parse('01/01/2010') );
insert pkgVer;

Lead ld = new Lead(
	LastName	= 'Customer',
	FirstName	= 'Test',
	Company		= 'MyTestCompany',
	Email		= 'test@MyTestCompany.com',
	sfLma__Subscriber_Org_Type__c = 'EE' );
insert ld;

sfLma__License__c testLic = new sfLma__License__c(
    	sfLma__Subscriber_Org_ID__c = UserInfo.getOrganizationId(),
    	sfLma__Used_Licenses__c=22 );
insert testLic;

System.debug([Select sfLma__Used_Licenses__c, sfLma__Subscriber_Org_ID__c, sfLma__Status__c, sfLma__Seats__c, sfLma__Proxy_User__c, sfLma__Package_Version__c, sfLma__Package_License_ID__c, sfLma__Licensed_Seats__c, sfLma__License_Type__c, sfLma__License_Status__c, sfLma__Lead__c, sfLma__Install_Date__c, sfLma__Help__c, sfLma__Expiration__c, sfLma__Expiration_Date__c, sfLma__Contact__c, sfLma__Account__c, RecordTypeId, Name, Id From sfLma__License__c WHERE Id=:testLic.Id]);


update testLic;




-       Andy


I don't believe that will work. You are trying to active a license record that doesn't exist in the subscriber org. When you are inserting the license, you are setting it to an org Id. But there is no real LMA license in that org, so when you update it, it will fail activation. 


Why do you need to write LMA test methods? 

Andy Freeston_LarterAndy Freeston_Larter

Thanks for the response. I have built a self-service portal for my customers so they can purchase our products online. I obviously need to test the activation system before we start accepting money. Using a fake license allows me to reset the system so I can test all the possible scenarios. I really don’t want to repeatedly request new test orgs to act as fake customers.


I had assumed the LMA developers would have anticipated this need and have written the code to allow it to be tested, either by setting certain license values to null or to hard-coded ids. There must be some mechanism as they to test the LMA system themselves.





Did you make any progress with this? I am having the same issue. We wan't to automate the provisioning of licenses and this is done in Apex but I am unable to test our logic.





Andy Freeston_LarterAndy Freeston_Larter

No sorry, we couldn't do any automated testing. We had to rely on manual testing by installing products into an org.

- Andy