function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shane K 15Shane K 15 

Illegal assignment from List<SObject> to List<System.Location>

I have the following code:
String query = ' ';

query = 'SELECT Id, Name FROM Location ';
        
List <Location> Locations = database.Query(query);

I am getting an error: Illegal assignment from List<SObject> to List<System.Location>
VinayVinay (Salesforce Developers) 
Can you try below.
Location loc = Database.Query('SELECT Id FROM Location');
List<Location> locs = Database.Query('SELECT Id FROM Location');

Please mark as Best Answer if above information was helpful.

Thanks,
Shane K 15Shane K 15
Hi Vinay,

I am getting the same error with your suggestion.
MenteeMentee
Hi Shane, there is class which is System.location and you are trying to assign it list of Sobject
do you have customObject that you are trying to query or tell me what are you trying acheive?There is an example here to use Location (https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_system_Location.htm#apex_class_system_Location) . let me know if it is still not resolved.
Ben C 5Ben C 5

I am getting the same error message.  I am trying the following:

List<Location> myLocations = [SELECT Id, Name FROM Location];
Ben C 5Ben C 5

This seems to work though:

List<SObject> myLocations =  [SELECT Id, Name FROM Location];