You need to sign in to do that
Don't have an account?
ZoomV
Variable does not exist in trigger test
I've put together the following test for a trigger.
@isTest public with sharing class AutoCreateSubsTriggerTest { static testMethod void testAutoCreateSubs() { // First, set up your test User. User testUser = generateTestUser(); // Generate your position but don't perform DML yet Contract_Overview__c contover = new Contract(Subsidiaries_On_Contract__c = testUser.Id); // Start your test and insert your contract overview Test.startTest(); insert contover; Test.stopTest(); // Get the subs from the DB to ensure they were created List<Subs_Serviced_On_Contract__c> subs = [SELECT Id FROM Subs_Serviced_On_Contract__c WHERE Contract_Overview__c = :contover.Id ]; // There should be 1 interviewer because only one user ID was provided System.assert(1, subs.size(), 'One sub object is expected'); } private User generateTestUser(){ // We use the System Admin profile because it will always be there Profile sysAdmin = [SELECT Id FROM Profile WHERE Name = 'System Administrator' LIMIT 1 ]; // Generate the user User newUser = new User( UserName = 'unit.tester@example.com', LastName = 'Test', FirstName = 'Jane', Email = 'unit.tester@example.com', phone = '555-555-5555', MobilePhone = '555-555-5554', Street = '123 Fake Street', City = 'Los Angeles', State = 'CA', PostalCode = '12345', CommunityNickName = 'unit.test', Alias = 'abcd', ProfileId = sysAdmin.Id, emailencodingkey = 'UTF-8', languagelocalekey = 'en_US', localesidkey = 'en_US', timezonesidkey = 'America/Los_Angeles' ); // Insert that user insert user; return user; } }
I am getting the error "Variable does not exist : user". I don't understand how that's happening. Anybody got an idea ?
Thank you.
you are trying to insert user instead of newUser
All Answers
you are trying to insert user instead of newUser
Thanks Naidu - totally missed that.
Naidu,
I am now getting a "Save Error : Method does not exist or incorrect signature : generateTestUser()" for this line :
I need to make it static, but I'm not sure how I would do that in this particular code ... ?
Thank you for any help.
can you change this method like the one above and try. Let me know whats happening.
Naidu - I'm not sure what you're saying to do here. Is this what you are asking me to change the code to ? :
I'm getting a "Save Error : Method does not exist or incorrect signature: generateTestUser()" error
along with :
"Save Error : Only top-level class variables can be declared static"
Thank you for your help.
try this,.
Thank you Naidu,
I am now getting this error : "Save error : unexpected token 'Static'" for this line :
Thank you very much for your time & effort.
try this... It should not thrown the error for static key word.. but try this let me know if it doesnt work.
Naidu,
I'm still getting the same error. ( Save error : unexpected token 'static').
Now it's for this line :
Thank you for your help.
Naidu,
just fyi : I got it working with this code :
Thank you very much for your help & effort.