You need to sign in to do that
Don't have an account?
Patcs
Error in Query
Account acc = new Account(Name='Test1',Type='Prospect',Country_Listing__c='India',RecordTypeId='XXXXXXXXX');
insert(acc);
Account acc1=[select Name,id from Account where id=:acc.Id limit 1];
opportunity opp1=new opportunity(Account=acc1.Name,Name='test5',CloseDate=system.Today());
This is the Query written in test class.when i try to insert like this it throws an error
Error: Compile Error: Invalid initial expression type for field Account, expecting: SOBJECT:Account (or single row query result of that type) at line 14 column 25
Thanks
All Answers
Use like this...
Account acc = new Account();
acc.Name='Test1';acc.Type='Prospect';
acc.Country_Listing__c='India';
acc.RecordTypeId='XXXXXXXXX';
insert acc;
Account[] acc1=[select Name,id from Account where id=:acc.Id limit 1];
opportunity opp1=new opportunity(Account=acc1[0].Name,Name='test5',CloseDate=system.Today());
To the best of my knowledge, lookup fields are references and hold the Id, rather than the name !
In my opinion, it should read
opportunity opp1=new opportunity(Account=acc1.Id ,Name='test5',CloseDate=system.Today());
Thanks. It worked well.