I am creating a Unit test for my class that uses two different object for some reason I cant get access This is the unit test

prequalAPI.QualifyLocationResponse qualResponse = new prequalAPI.QualifyLocationResponse();
         qualResponse.QualifyLocationId = 'ABC123';
         qualResponse.ValidAddresses = new List<prequalAPI.QualifyLocationValidAddress>();

///// PrequalClass

 public class QualifyLocationResponse {

        public String QualifyLocationId { get; set; }
        public List<QualifyLocationValidAddress>  ValidAddresses  { get; set; }

 public class QualifyLocationValidAddress 
        public string ProviderName {get;set;}


this gives me the following error

Initial term of field expression must be a concrete SObject: List

List(); qualResponse.ValidAddresses.ProviderName.add('test');


You are trying to set ProviderName on a List<PrequalApi.QualifyLocationValidAddress>, and the List class does not have any such member. Probably what you meant to do was add an instance of that wrapper class with that property set:

PrequalApi.QualifyLocationValidAddress validAddress =
    new PrequalApi. QualifyLocationValidAddress();
validAddress.providerName = 'Populated';

PrequalApi.QualifyLocationResponse response = new PrequalApi.QualifyLocationResponse();
response.qualifyLocationId = '...';
response.validAddresses = new List<PrequalApi.QualifyLocationValidAddress>

Or you could rewrite that last line as two if you prefer:

response.validAddresses = new List<PrequalApi.QualifyLocationValidAddress>();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.