3

I'm very new to Salesforce development and I'm writing this class to return some queries from the Location_Tracing_c:

public class CTLocationTracingController{
    
    /**Get last 30 days visitors 
    //@return List<Location_Tracing_c> 
    */
    public static List<Location_Tracing_c> getVisitors(String locationId){
        return [SELECT Id, Person__c, Location__c, Visit_Date__c, Person__r.Health_Status__c, Person__r.Token__c 
                FROM Location_Tracing__c 
                WHERE Id =: locationId 
                ORDER BY Visit_Date__c DESC] ;
    }

    /**Get all location ids for visitors 
    //@return List<Location_Tracing_c> 
    */
    public static List<Location_Tracing_c> getLocationsByPersonIds(Set<Id> personIds){
        return [SELECT Id, Person__c, Location__c 
                FROM Location_Tracing__c 
                WHERE Person__c IN :personIds 
                AND Visit_Date__c = LAST_N_DAYS:10] ;
    }

    /**Get all visitor ids for locations 
    //@return List<Location_Tracing_c> 
    */
    public static List<Location_Tracing_c> getLocationsByLocationsIds(Set<Id> locationIds){
        return [SELECT Id, Name, Person__c, Location__c, Visit_Date__c 
                FROM Location_Tracing__c 
                WHERE Location__c IN: locationIds 
                AND Visit_Date__c = LAST_N_DAYS:10
                AND Person__r.Health_Status__c = 'Green'] ;
        }
    
}

But I'm getting this error basically for all my methods :

Invalid type: Location_Tracing_c (26:44)                                            
Illegal conversion from List<Location_Tracing__c> to List<Location_Tracing_c> (17:9)

I'm not sure what i'm doing wrong. Any help is highly appreciated.

1 Answer 1

6

Welcome to Salesforce, and welcome to the salesforce stack exchange!

Your issue here is basically a spelling/keying error. The return value for all of your methods is "Location_Tracing_c", which only has one underscore between "Tracing" and "c". Custom objects always end with "__c", which has two underscores followed by a "c".

The SOQL queries however are correct, having both underscores. So thus the compiler thinks that you're trying to convert a list of __c to a list of _c, which is invalid. In addition, there are no apex types of the _c variety, so you're getting the "Invalid Type" error.

5
  • 1
    Oh my god! That was it! It worked! Thank you so much! I feel so stupid now. I was checking through all my SOQL queries to make sure there was no error but never saw this. And the compiler error is so deceptive! Thanks again! Apr 23, 2021 at 18:23
  • 1
    @AslahPHussain Don't forget to mark Nathanael's answer as Best Answer! :) Apr 23, 2021 at 18:43
  • @VictorL I've upvoted it but you need at least 15 reputation to cast a vote, but my feedback has been recorded. Apr 23, 2021 at 19:38
  • 1
    @AslahPHussain There should be a gray checkmark next to the answer to click (which is different from the upvote). Marking as best answer will award Nathanael reputation and will make sure the question shows up in the search results as an answered question. Apr 23, 2021 at 19:52
  • np, glad it worked! Apr 26, 2021 at 15:45

You must log in to answer this question.

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