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
Terry411Terry411 

Deployment Error No Such Column Exists

I'm getting the following error:

System.QueryException: No such column 'Location__c' on entity 'Special_Event__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. 
Stack Trace: Class.ORC.<init>: line 81, column 1 Class.ORTests.testORC: line 196, column 1
  • Special_Event__c.Location__c does exist and its a GeoLocation field type
  • It is visable to all profiles.  
  • Special_Event__c is Deployed.
  • I've updated the class to API 38 thinking perhaps it's prior API version didn't support GeoLocation but that didn't help
  • I tried rewriting the soql statement to a string with a database.execute() statement but again no luck.
I'm out of ideas.  Please help with any other idea
Best Answer chosen by Terry411
Terry411Terry411
I ended up creating a simple vf page and controller that only performed the query upon pressing a button.  I was able to deploy this into production and the query worked just fine.  I then added a test class to this trimmed down piece of code and as soon at the test class called the Database.Query(q); the test would fail.  To fix this, I did the following and it works perfectly now.
list<Special_Event__c> seList = new list<Special_Event__c>();
if (! Test.isRunningTest()) seList = Database.query(q);

 

All Answers

Jasper WallJasper Wall
Hi,
Add Location__c fields to your outbound changeset and start your deployment.

Let us know if it helps,

Thanks,
Balayesu
Terry411Terry411
Hi Balayesu, thanks for the quick reply.  I tried that as well and had no luck :(
rajat Maheshwari 6rajat Maheshwari 6
Hi Terry,

Could you please paste the query which you are using , over here?

Thanks
Terry411Terry411
Here's the SOQL.  This does run successfully in the Query Editor when I run it against the production envioronment.  I keep questioning if it's not somehow geolocation related but I have other code using geolocation fields on a different object that deploys fine.  

        map<Id, Special_Event__c> seMap = new map<Id, Special_Event__c>([select id, Name, Event_Date__c, Site_Address_Line__c, 
                            Site_Contact__r.Physical_Zip_Postal_Code__c, Total_Appointments__c, 
                            Scheduled_Appointments__c, Scheduling_Notes__c 
                        from Special_Event__c 
                        where Type__c = :searchType  
                            and Event_Date__c > :searchDateTime
                            and DISTANCE(Location__c, GEOLOCATION(:latitude, :longitude), 'mi') < :decimal.valueOf(radius)
                        order by DISTANCE(Location__c, GEOLOCATION(:latitude, :longitude), 'mi')
                        limit 10]);
 
rajat Maheshwari 6rajat Maheshwari 6

Hi Terry,

Please visit this link, and check : - 

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_geolocate.htm

 

Thanks

Terry411Terry411
@rajat, that's the link I used to model my code from.  Is there something specifically there that you saw that I wasn't following correctly?
Terry411Terry411
I see that it doesn't support data binding in the SOQL so I switched to this which continues to get the same error message:

        string q = 'select id, Name, Event_Date__c, Site_Address_Line__c,';
        q += ' Site_Contact__r.Physical_Zip_Postal_Code__c, Total_Appointments__c, Scheduled_Appointments__c, Scheduling_Notes__c';
        q += ' from Special_Event__c';
        q += ' where Type__c = \'' + searchType + '\'';
        q += ' and Event_Date__c > ' + searchDateTime;
        q += ' and DISTANCE(Location__c, GEOLOCATION(' + String.valueOf(latitude) + ',' + String.valueOf(longitude) + '), \'mi\') < ' + radius;
        q += ' order by DISTANCE(Location__c, GEOLOCATION(' + String.valueOf(latitude) + ',' + String.valueOf(longitude) + '), \'mi\')';
        q += ' limit 10';
        system.debug('******************* q: ' + q);
        list<Special_Event__c> seList = Database.query(q);
 
Terry411Terry411
Any other thoughts on this?  Its being frustrating trying to get past something that should be easy.
Terry411Terry411
I've been doing more testing on this.  
- I recreated the Location__c field in production.  Deployment FAILED:  System.QueryException: No such column 'Location__c' 
- I modified the query string to remove the DISTANCE( ) lines from the WHERE & ORDER BY clause.  Deployment VALIDATES 
- I modified the query string to include Location__Latitude__s and Location__Longitude__s fields with DISTANCE ( ) lines still removed.  Deployment VALIDATES
- I added the DISTANCE( ) lines back into the ORDER clause left it out of the WHERE clause.  Deployment FAILED
- I added the DISTANCE( ) lines back into the WHERE clause and left out the ORDER clause.  Deployment FAILED

Here's the query in code:
string q = 'select id, Name, Event_Date__c, Site_Address_Line__c, Location__Latitude__s, Location__Longitude__s,';
q += ' Site_Contact__r.Physical_Zip_Postal_Code__c, Total_Appointments__c, Scheduled_Appointments__c, Scheduling_Notes__c';
q += ' from Special_Event__c';
q += ' where Type__c = \'' + searchType + '\'';
q += ' and Event_Date__c > ' + searchDateTime;
q += ' and DISTANCE(Location__c, GEOLOCATION(' + String.valueOf(latitude) + ',' + String.valueOf(longitude) + '), \'mi\') < ' + radius;
q += ' order by DISTANCE(Location__c, GEOLOCATION(' + String.valueOf(latitude) + ',' + String.valueOf(longitude) + '), \'mi\')';
q += ' limit 10';

system.debug('******************* q: ' + q);
list<Special_Event__c> seList = Database.query(q);

Here's how the query looks via the debug log:
 
[30]|DEBUG|******************* q: select id, Name, Event_Date__c, Site_Address_Line__c, Site_Contact__r.Physical_Zip_Postal_Code__c, Total_Appointments__c, Scheduled_Appointments__c, Scheduling_Notes__c from Special_Event__c where Type__c = 'Public' and Event_Date__c > 2017-02-12T13:51:00z and DISTANCE(Location__c, GEOLOCATION(41.564346,-93.6236969), 'mi') < 50 order by DISTANCE(Location__c, GEOLOCATION(41.564346,-93.6236969), 'mi') limit 10

If I copy this query into the run anonymous window in production, it works perfectly fine.  All the code is version 38 with is compatible in both production and sandbox.
Terry411Terry411
I ended up creating a simple vf page and controller that only performed the query upon pressing a button.  I was able to deploy this into production and the query worked just fine.  I then added a test class to this trimmed down piece of code and as soon at the test class called the Database.Query(q); the test would fail.  To fix this, I did the following and it works perfectly now.
list<Special_Event__c> seList = new list<Special_Event__c>();
if (! Test.isRunningTest()) seList = Database.query(q);

 
This was selected as the best answer