[SOQL]: Reference Id field on a custom object without dot notation?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}
up vote
2
down vote
favorite
I know that with standard objects one can do AccountId
instead of Account.Id
inside a SOQL query. Is it possible to do the same for custom objects, say for My_Object__c
? Is there a way to reference the Id without using a dot .
notation?
I am currently getting the following error if I use the dot notation: The left operand 'My_Object__r.Id' cannot have more than one level of relationships
.
I get this when executing the following query:
SELECT
Id,
My_Object__r.Some_Field__c
FROM Opportunity
WHERE My_Object__r.Id IN (SELECT Id FROM My_Object__c WHERE Name LIKE '%myobjectname%')
LIMIT 1
soql
add a comment |
up vote
2
down vote
favorite
I know that with standard objects one can do AccountId
instead of Account.Id
inside a SOQL query. Is it possible to do the same for custom objects, say for My_Object__c
? Is there a way to reference the Id without using a dot .
notation?
I am currently getting the following error if I use the dot notation: The left operand 'My_Object__r.Id' cannot have more than one level of relationships
.
I get this when executing the following query:
SELECT
Id,
My_Object__r.Some_Field__c
FROM Opportunity
WHERE My_Object__r.Id IN (SELECT Id FROM My_Object__c WHERE Name LIKE '%myobjectname%')
LIMIT 1
soql
1
instead of My_Object__r.Id you can just use My_Object__c
– Pranay Jaiswal
10 hours ago
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I know that with standard objects one can do AccountId
instead of Account.Id
inside a SOQL query. Is it possible to do the same for custom objects, say for My_Object__c
? Is there a way to reference the Id without using a dot .
notation?
I am currently getting the following error if I use the dot notation: The left operand 'My_Object__r.Id' cannot have more than one level of relationships
.
I get this when executing the following query:
SELECT
Id,
My_Object__r.Some_Field__c
FROM Opportunity
WHERE My_Object__r.Id IN (SELECT Id FROM My_Object__c WHERE Name LIKE '%myobjectname%')
LIMIT 1
soql
I know that with standard objects one can do AccountId
instead of Account.Id
inside a SOQL query. Is it possible to do the same for custom objects, say for My_Object__c
? Is there a way to reference the Id without using a dot .
notation?
I am currently getting the following error if I use the dot notation: The left operand 'My_Object__r.Id' cannot have more than one level of relationships
.
I get this when executing the following query:
SELECT
Id,
My_Object__r.Some_Field__c
FROM Opportunity
WHERE My_Object__r.Id IN (SELECT Id FROM My_Object__c WHERE Name LIKE '%myobjectname%')
LIMIT 1
soql
soql
asked 11 hours ago
Arthlete
793515
793515
1
instead of My_Object__r.Id you can just use My_Object__c
– Pranay Jaiswal
10 hours ago
add a comment |
1
instead of My_Object__r.Id you can just use My_Object__c
– Pranay Jaiswal
10 hours ago
1
1
instead of My_Object__r.Id you can just use My_Object__c
– Pranay Jaiswal
10 hours ago
instead of My_Object__r.Id you can just use My_Object__c
– Pranay Jaiswal
10 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
Yes. For some custom relationship from child to parent My_Object__r
, your Id will be My_Object__c
, and you can reference that field in your SOQL query without performing a join/traversing the relationship. (In fact, it is preferable that you do so!)
The place you have to go somewhere special to determine the relationship name is when you're querying from parent to child, where you locate the child relationship name on the configuration of the lookup on the child.
Here, going from child to parent, your relationship name and Id field name are both derived directly from the API name of the lookup field. The Id field is just the lookup field; the relationship is the lookup field with __r
.
I completely missed that! Thank you!
– Arthlete
10 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Yes. For some custom relationship from child to parent My_Object__r
, your Id will be My_Object__c
, and you can reference that field in your SOQL query without performing a join/traversing the relationship. (In fact, it is preferable that you do so!)
The place you have to go somewhere special to determine the relationship name is when you're querying from parent to child, where you locate the child relationship name on the configuration of the lookup on the child.
Here, going from child to parent, your relationship name and Id field name are both derived directly from the API name of the lookup field. The Id field is just the lookup field; the relationship is the lookup field with __r
.
I completely missed that! Thank you!
– Arthlete
10 hours ago
add a comment |
up vote
3
down vote
Yes. For some custom relationship from child to parent My_Object__r
, your Id will be My_Object__c
, and you can reference that field in your SOQL query without performing a join/traversing the relationship. (In fact, it is preferable that you do so!)
The place you have to go somewhere special to determine the relationship name is when you're querying from parent to child, where you locate the child relationship name on the configuration of the lookup on the child.
Here, going from child to parent, your relationship name and Id field name are both derived directly from the API name of the lookup field. The Id field is just the lookup field; the relationship is the lookup field with __r
.
I completely missed that! Thank you!
– Arthlete
10 hours ago
add a comment |
up vote
3
down vote
up vote
3
down vote
Yes. For some custom relationship from child to parent My_Object__r
, your Id will be My_Object__c
, and you can reference that field in your SOQL query without performing a join/traversing the relationship. (In fact, it is preferable that you do so!)
The place you have to go somewhere special to determine the relationship name is when you're querying from parent to child, where you locate the child relationship name on the configuration of the lookup on the child.
Here, going from child to parent, your relationship name and Id field name are both derived directly from the API name of the lookup field. The Id field is just the lookup field; the relationship is the lookup field with __r
.
Yes. For some custom relationship from child to parent My_Object__r
, your Id will be My_Object__c
, and you can reference that field in your SOQL query without performing a join/traversing the relationship. (In fact, it is preferable that you do so!)
The place you have to go somewhere special to determine the relationship name is when you're querying from parent to child, where you locate the child relationship name on the configuration of the lookup on the child.
Here, going from child to parent, your relationship name and Id field name are both derived directly from the API name of the lookup field. The Id field is just the lookup field; the relationship is the lookup field with __r
.
edited 10 hours ago
answered 10 hours ago
David Reed
27k51745
27k51745
I completely missed that! Thank you!
– Arthlete
10 hours ago
add a comment |
I completely missed that! Thank you!
– Arthlete
10 hours ago
I completely missed that! Thank you!
– Arthlete
10 hours ago
I completely missed that! Thank you!
– Arthlete
10 hours ago
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f241266%2fsoql-reference-id-field-on-a-custom-object-without-dot-notation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
instead of My_Object__r.Id you can just use My_Object__c
– Pranay Jaiswal
10 hours ago