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
Jason Kuzmak 12Jason Kuzmak 12 

Unable to query child object records by recently changed name

Hi all, 

I'm having a problem related child objects using SOQL. In preparation for another object that has yet to be created, I made corrections to my custom object name, though now I can only query related child records using the old (wrong) name. My code here shows that now, the system recognizes both:


 
// Query child "Checklist_Item_Junctions__r" even though that is no longer the object's name
List<Checklist_Template__c> templateQuery = [Select Id, Machine_Series__c, (Select Id, Checklist_Template__c, Checklist_Template_Item__c From Checklist_Item_Junctions__r) From Checklist_Template__c];
        
        
        // separately query all "Checklist_Template_Item_Junction__c" records, (the new name of the object)
        List<Checklist_Template_Item_Junction__c> junctionQuery = [Select Id, Checklist_Template__c, Checklist_Template_Item__c From Checklist_Template_Item_Junction__c];
       

This saves successfully, and I have no idea why. There is no longer such an object as "Checklist_Item_Junction__c", but it's requiring that I call it that in my child relationship query.
 
Best Answer chosen by Jason Kuzmak 12
Dushyant SonwarDushyant Sonwar
Hi Jason ,

Try going to the lookup field of custom object and check whether the name of child relationship is correct or not . Rename it with name that you want to use.
User-added image

Hope this helps :)

All Answers

Jason Kuzmak 12Jason Kuzmak 12
Here are some additional screenshots demonstrating that all available object names have been changed:
Fields have been updated



and that there is not also an object called "Checklist Item Junction" in my list of objects anymore:
User-added image
 
Raj VakatiRaj Vakati
Change it as below 
 
// Query child "Checklist_Item_Junctions__r" even though that is no longer the object's name
List<Checklist_Template__c> templateQuery = [Select Id, Machine_Series__c, (Select Id, Checklist_Template__r.Name, Checklist_Template_Item__c From Checklist_Item_Junctions__r) From Checklist_Template__c];
        
        
        

 
Jason Kuzmak 12Jason Kuzmak 12
Hi Raj,

Nothing happened. It still accepts the old incorrect object name. 
Dushyant SonwarDushyant Sonwar
Hi Jason ,

Try going to the lookup field of custom object and check whether the name of child relationship is correct or not . Rename it with name that you want to use.
User-added image

Hope this helps :)
This was selected as the best answer
Dushyant SonwarDushyant Sonwar
In you case , you need to navigate to the checklist template item junction object and find the lookup or master detail field relating to checklist template.

Fyi , when you edit and save the relationship name it may give reference error as your code might be using the old child relationship name , so code commenting will be needed for this.
Jason Kuzmak 12Jason Kuzmak 12

@Dushyant Sonwar

I think that did it! Thanks very much!