Hi i'm trying to right a test class for an apex class that is only soql querying records. all the object in this code are Standard object by Salesforce.

my Apex Class:

public with sharing class RetailStoreList {

@AuraEnabled(cacheable = true)
public static List<RetailStore> fetchStores(){
    return [SELECT Name, Location__c, Account.Name, Website__c, 
            From RetailStore Limit 120];


I'm not sure how to write the test class for the above apex class.

public class RetailStoreList_Test {
    static testmethod void testRetailStoreList(){

            // create Test Account
            Account acc = new Account(name='some account',
            insert acc;

             //create test Location record
            Location locc = new Location( );
            locc.Name = 'Location Name';
            locc.LocationType = 'Site';
            insert locc;

            RetailStore store = new RetailStore();
            store.Name = 'Test Store';
            store.Location__c='some location';
            store.AccountId= acc.Id;

            insert store;

            RetailStoreList retSt = new RetailStoreList();
            System.assertNotEquals(null, RetailStoreList.fetchStores() );


enter image description here

enter image description here

  • Please edit your question to describe the specific failure, including the actual location and error message.
    – David Reed
    Apr 18, 2020 at 0:02
  • Hi @DavidReed i did add the screenshots or the errors.
    – Templar
    Apr 18, 2020 at 0:11

1 Answer 1


The errors are telling you what the compiler thinks the issue is. As far as it's concerned, Location is not an sObject; all of the other errors are consequences of that type not meaning to the compiler what you intend it to mean.

Location is part of Field Service Lightning, and the SOAP Reference for that object points to the issue:

“Location” in Salesforce can also refer to the geolocation compound field found on many standard objects. When referencing the Location object in your Apex code, always use Schema.Location instead of Location to prevent confusion with the standard Location compound field. If referencing both the Location object and the Location field in the same snippet, you can differentiate between the two by using System.Location for the field and Schema.Location for the object.

Emphasis mine. You'll need to refer to Schema.Location in Apex to avoid having it interpreted as a reference to the Location class, representing a geolocation field.

Your sandbox will also need to have Consumer Goods Cloud and Field Service Lightning available.

  • i'm using Consumer Goods Cloud and Retail Store is part of the package. to my understand "Location" is a standard object in SF. all i need is a test class to cover that SOQL query APEX class, i'm not sure why it errors. I'm using sandbox and not scratch ORG if that helps.
    – Templar
    Apr 18, 2020 at 1:16
  • Okay, I think I see what the actual problem is; edited above.
    – David Reed
    Apr 18, 2020 at 1:21
  • Schema.Location was indeed the answer. Thank you David
    – Templar
    Apr 18, 2020 at 11:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .