0

Error: Compile Error: Didn't understand relationship 'JobAllocation__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 19 column 22

 for(Job__c job : [Select Id, Opportunity__c ,(Select Name,   job__c From JobAllocation__c order by CreatedDate desc limit 1) 
   from Job__c where Opportunity__c = :opps order by CreatedDate desc]){}

job allocation and job having lookup relationship field job having opportunity lookup

1

JobAllocation__c is the object name, what you need is the relationship name.

Navigate to the JobAllocation__c object page in the UI, then click on the lookup field to Job__c.

There will be a field titled 'Child Relationship Name', this is the field you need. In your case it will probably be 'JobAllocations'.

Your final query would look like:

for(Job__c job : [Select Id, Opportunity__c ,(Select Name, job__c From JobAllocations__r order by CreatedDate desc limit 1) from Job__c where Opportunity__c = :opps order by CreatedDate desc])
0

On JobAllocation__c object you have a lookup or Master Detail to Job__c.

When you query from Job__c and want it's child records of type JobAllocation__c you need to use the correct name of the child relationship. This is probably JobAllocations__r (note the s for plural, this is the default)

Select Id, Opportunity__c,
  (Select Name, job__c From JobAllocations__r order by CreatedDate desc limit 1)
  from Job__c

You can confirm what the correct name is by

  1. Go to Create | Objects | JobAllocation and look at the field where you establish this relationship
  2. You will see an item "child relationship name" which gives the correct name you can use for querying from the parent
  • on job object i am having a lookup field for job allocation – ravi Oct 30 '15 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.