SOQL - Select only contacts that have related Opportunities
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I have the following SOQL:
SELECT Id, Name, (SELECT Id, Name FROM Opportunities) FROM Contact WHERE Email = 'test@test.com'
I want to restrict this to return only those contacts for which the related Opportunities list is not empty. How can I do this?
Thanks.
soql opportunity contact
add a comment |Â
up vote
1
down vote
favorite
I have the following SOQL:
SELECT Id, Name, (SELECT Id, Name FROM Opportunities) FROM Contact WHERE Email = 'test@test.com'
I want to restrict this to return only those contacts for which the related Opportunities list is not empty. How can I do this?
Thanks.
soql opportunity contact
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have the following SOQL:
SELECT Id, Name, (SELECT Id, Name FROM Opportunities) FROM Contact WHERE Email = 'test@test.com'
I want to restrict this to return only those contacts for which the related Opportunities list is not empty. How can I do this?
Thanks.
soql opportunity contact
I have the following SOQL:
SELECT Id, Name, (SELECT Id, Name FROM Opportunities) FROM Contact WHERE Email = 'test@test.com'
I want to restrict this to return only those contacts for which the related Opportunities list is not empty. How can I do this?
Thanks.
soql opportunity contact
soql opportunity contact
edited Sep 5 at 13:16
David Reed
20.5k31640
20.5k31640
asked Sep 5 at 13:15
Cosmin C.
83
83
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
This is a good place to apply a semi-join pattern, which is the most common query tool used to limit a query by the presence or absence of related objects. It is made only a little bit more complex here by the fact that Opportunity and Contact are related by a sort of junction object, OpportunityContactRole:
SELECT Id, Name, (SELECT Id, Name FROM Opportunities)
FROM Contact
WHERE Email = 'test@test.com'
AND Id IN (SELECT ContactId
FROM OpportunityContactRole)
Thanks, exactly what I needed
â Cosmin C.
Sep 6 at 7:55
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
This is a good place to apply a semi-join pattern, which is the most common query tool used to limit a query by the presence or absence of related objects. It is made only a little bit more complex here by the fact that Opportunity and Contact are related by a sort of junction object, OpportunityContactRole:
SELECT Id, Name, (SELECT Id, Name FROM Opportunities)
FROM Contact
WHERE Email = 'test@test.com'
AND Id IN (SELECT ContactId
FROM OpportunityContactRole)
Thanks, exactly what I needed
â Cosmin C.
Sep 6 at 7:55
add a comment |Â
up vote
5
down vote
accepted
This is a good place to apply a semi-join pattern, which is the most common query tool used to limit a query by the presence or absence of related objects. It is made only a little bit more complex here by the fact that Opportunity and Contact are related by a sort of junction object, OpportunityContactRole:
SELECT Id, Name, (SELECT Id, Name FROM Opportunities)
FROM Contact
WHERE Email = 'test@test.com'
AND Id IN (SELECT ContactId
FROM OpportunityContactRole)
Thanks, exactly what I needed
â Cosmin C.
Sep 6 at 7:55
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
This is a good place to apply a semi-join pattern, which is the most common query tool used to limit a query by the presence or absence of related objects. It is made only a little bit more complex here by the fact that Opportunity and Contact are related by a sort of junction object, OpportunityContactRole:
SELECT Id, Name, (SELECT Id, Name FROM Opportunities)
FROM Contact
WHERE Email = 'test@test.com'
AND Id IN (SELECT ContactId
FROM OpportunityContactRole)
This is a good place to apply a semi-join pattern, which is the most common query tool used to limit a query by the presence or absence of related objects. It is made only a little bit more complex here by the fact that Opportunity and Contact are related by a sort of junction object, OpportunityContactRole:
SELECT Id, Name, (SELECT Id, Name FROM Opportunities)
FROM Contact
WHERE Email = 'test@test.com'
AND Id IN (SELECT ContactId
FROM OpportunityContactRole)
answered Sep 5 at 13:20
David Reed
20.5k31640
20.5k31640
Thanks, exactly what I needed
â Cosmin C.
Sep 6 at 7:55
add a comment |Â
Thanks, exactly what I needed
â Cosmin C.
Sep 6 at 7:55
Thanks, exactly what I needed
â Cosmin C.
Sep 6 at 7:55
Thanks, exactly what I needed
â Cosmin C.
Sep 6 at 7:55
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f231316%2fsoql-select-only-contacts-that-have-related-opportunities%23new-answer', 'question_page');
);
Post as a guest
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
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
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