You need to sign in to do that
Don't have an account?

Compiling failing: Variable doesn't exist in test class
Hi all,
I am trying to discover why while compiling a test class method, this is telling me 'Variable doesn't exist' in the row:
I would appreciate if someone could tell me what I am doing wrong?:
I am trying to discover why while compiling a test class method, this is telling me 'Variable doesn't exist' in the row:
System.assertEquals(testEntitlement.Id
I would appreciate if someone could tell me what I am doing wrong?:
@isTest private static void EntitlementUpdate() { //ARRANGE User serviceUser = [ SELECT Id FROM User WHERE Email =: 'test.serviceuser@google.com' ]; Account testAccount = [ SELECT Id FROM Account]; Product2 testProduct = [ SELECT Id FROM Product2]; CaseAsset__c testCaseAsset = new CaseAsset__c(Name='Test Case Asset', Account__c=testAccount.Id, SerialNumber__c='123', Product__c = testProduct.Id, StartDate__c = System.today(), EndDate__c = System.today() + ); testCaseAsset.OwnerId = serviceUser.ID; insert testCaseAsset; //ACT test.startTest(); System.runAs(serviceUser){ Entitlement testEntitlement = new Entitlement(); testEntitlement.AccountID = testCaseAsset.Account__c; testEntitlement.Name = testCaseAsset.Name; testEntitlement.CasesPerEntitlement = integer.valueOf(testCaseAsset.NoOfCasesPerYear__c); testEntitlement.EndDate = testCaseAsset.EndDate__c; testEntitlement.StartDate = testCaseAsset.StartDate__c; testEntitlement.IsPerIncident = true; testEntitlement.CaseAsset__c = testCaseAsset.Id; testEntitlement.RemainingCases = integer.valueOf(testCaseAsset.NoOfCasesPerYear__c); insert testEntitlement; } test.stopTest(); //ASSERT Entitlement testEntitlementAfterProcess = [ SELECT Id, Name FROM Entitlement ]; System.assertEquals(testEntitlement.Id, testEntitlementAfterProcess.Name, 'Entitlement not created'); }
just put the Entitlement testEntitlement = new Entitlement(); above the User.runAs() line.
As Randi Warner mentioned you should take the Entitlement testEntitlement; declaration outside of the System.runAs(){ ... } It could be like:
I hope this helps