You need to sign in to do that
Don't have an account?
LloydSilver
Error: Invalid initial expression type for field Account
Working on a test class. I'm getting the error:
"Invalid initial expression type for field Account, expecting: SOBJECT:Account(or single row query result of that type). I'm new, and am at wit's end trying to figure this out. I'd appreciate some help. Thanks.
@isTest private class TestOpportunityAgentStatus { static testMethod void myUnitTest() { Profile pf = [Select Id from Profile where Name = 'System Administrator']; User u = new User(); u.FirstName = 'Test'; u.LastName = 'User'; u.Email = 'testuser@test123456789.com'; u.CompanyName = 'test.com'; u.Title = 'Test User'; u.Username = 'testuser@test123456789.com'; u.Alias = 'testuser'; u.CommunityNickname = 'Test User'; u.TimeZoneSidKey = 'America/Mexico_City'; u.LocaleSidKey = 'en_US'; u.EmailEncodingKey = 'ISO-8859-1'; u.ProfileId = pf.Id; u.LanguageLocaleKey = 'en_US'; insert u; system.runAs(u){ Account xxxacc1 = new Account(Name = 'Test Company'); insert xxxacc1; Contact xxxcon1 = new Contact(FirstName = 'Test', LastName = 'Guy', Account = xxxacc1.Id); insert xxxcon1; Opportunity xxxopp1 = new Opportunity( Name = 'Test Company - New Opp', Account = xxxacc1.Id, CloseDate = Date.today(), StageName = 'Prospecting' ); insert xxxopp1; OpportunityContactRole xxxocr1 = new OpportunityContactRole( ContactID = xxxcon1.Id, OpportunityId = xxxopp1.Id, Role = 'Decision Maker' ); insert xxxocr1; } } }
Opportunity xxxopp1 = new Opportunity(
Name = 'Test Company - New Opp',
AccountId = xxxacc1.Id,
CloseDate = Date.today(),
StageName = 'Prospecting'
);
All Answers
Hello,
Try to use:
Contact xxxcon1 = new Contact(FirstName = 'Test', LastName = 'Guy', AccountId = xxxacc1.Id);
Thanks for the response. Unfortunately I got the same error message.
Opportunity xxxopp1 = new Opportunity(
Name = 'Test Company - New Opp',
AccountId = xxxacc1.Id,
CloseDate = Date.today(),
StageName = 'Prospecting'
);
Perfect. Thanks!