+ Start a Discussion
TheresaAndersonTheresaAnderson 

Compile Error: Initial term of field expression must be a concrete SObject: LIST<Account>

@isTest

public class testCreateAssetonClosedWon {
   
    static testMethod void testCreateAssetonClosedWon(){
       
        List<Account> a = [select Id, CurrencyIsoCode, name from Account where Id = 'wwwwwwww'];
        Opportunity o = new Opportunity();
        Quote q = new Quote();
        QuoteLineItem ql = new QuoteLineItem();

// create opportunity for testing
       
        o.AccountId = a.Id;  (line with error)
        o.Name = a.name + ' - test';
        o.StageName = 'Stage 3: Commit Funding';
        o.type = 'vvvvvvvvvvvvvvv';
        o.Line_of_Business__c = 'North America';
        o.license__c = 'Existing';
        o.CurrencyIsoCode = a.CurrencyIsoCode;
        o.CloseDate = date.today();
        insert o;

// create software quote for testing

        q.Name = a.name + ' - Quote test';
        q.OpportunityId = o.Id;
        q.erp__c = 'SAP';
        q.contactId = 'xxxxxx';
        q.ExpirationDate = date.today() + 30;
        insert q;
       
//create quote line items

        PricebookEntry pbID = [select Id, CurrencyIsoCode from PricebookEntry where PriceBook2ID = 'xxxxxxxxxxxxxxxxxx'
                              and CurrencyIsoCode = 'USD' and Id = 'xxxxxxxxxf' Limit 1];
        ql.QuoteId = q.Id;
        ql.Quantity = 100;
        ql.UnitPrice = 1188.00;
        ql.PricebookEntryId = pbId.Id;
        insert ql;
       
        q.status = 'Approved';
        q.Approval_Level__c = 'Approved';
        q.Quote_Approved__c = True;
//        q.IsSyncing = True;
        update q;
       
        o.StageName= 'Stage 7: Closed/Won';
        update o;
    }
}

stcforcestcforce

you're trying to get the name from a list rather than an individual instance. do you mean a[0].name?

stcforcestcforce

well, a[0].id but you get my drift.

TheresaAndersonTheresaAnderson

Thank you.  I made the change and the class is combiling.  When I execute the test, I receive ' System.QueryException: List has no rows for assignment to SObject'.

stcforcestcforce

If in doubt regarding a query recieving back any results you can place the query in a try block or can set the result to an array.

someObject x = []; //some query with one result or multiple.

if(!x.isEmpty) {}

stcforcestcforce

oops,

i meant someObject[] x = [some query]

or list<someObject> x = [somequery]

stcforcestcforce

You need to have a look at what you're searching for in terms of ids. i think if those are expected ids, then you might be labouring under a couple incorrect notions. Ids are generated by the system and have a specific form. For a couple of those searches, i can't think of any situation in which you would return results.