You need to sign in to do that
Don't have an account?
MVJ
SOQL Questions - Using In Clause
In trying to keep within the governors limits for APEX I am trying to limit the
number of records that get returned in a SOQL Query.
I need to find Opportunities that DO NOT have a Contact role tied it when the opportunity moves into a specific stage.
Since there is a limit to the number of records that can be returned within an APEX Trigger I wanted to only get the Opportunity Id's that do not have the contact role.
To do this on one offs is easy. The problem is trying to write the routine for bulk updates/inserts.
I want to get just the unique Id's that have at least on Contact Role defined. I need the following Query to get that list.
I tried the following Query on the Apex Explorer and get a Malformed Query error. Is does not like the Select in the In Clause.
SELECT Id from Opportunity Where Id in (Select OpportunityId from OpportunityContactRole where OpportunityId in ('006T0000002FSIv','006T0000003LFwJ'))
In the example that I have above I expected to get back on Opty Id. Of the two listed on one of them has a contact linked to it.
I am just trying to test out my theory before I start writing code that may not be possible. If I understand the limits I can only return 1,000 records in the resulting Query. If I make the call and pull back all the records from the OportunityContactRole it is possible that I can exceed the 1,000 record limit. If I get the query above to work that will make me return at most the number of records that are in the Trigger.
Thanks in advance for any help.
I need to find Opportunities that DO NOT have a Contact role tied it when the opportunity moves into a specific stage.
Since there is a limit to the number of records that can be returned within an APEX Trigger I wanted to only get the Opportunity Id's that do not have the contact role.
To do this on one offs is easy. The problem is trying to write the routine for bulk updates/inserts.
I want to get just the unique Id's that have at least on Contact Role defined. I need the following Query to get that list.
I tried the following Query on the Apex Explorer and get a Malformed Query error. Is does not like the Select in the In Clause.
SELECT Id from Opportunity Where Id in (Select OpportunityId from OpportunityContactRole where OpportunityId in ('006T0000002FSIv','006T0000003LFwJ'))
In the example that I have above I expected to get back on Opty Id. Of the two listed on one of them has a contact linked to it.
I am just trying to test out my theory before I start writing code that may not be possible. If I understand the limits I can only return 1,000 records in the resulting Query. If I make the call and pull back all the records from the OportunityContactRole it is possible that I can exceed the 1,000 record limit. If I get the query above to work that will make me return at most the number of records that are in the Trigger.
Thanks in advance for any help.
The APEX Code above identifies the records that do not have an contact related to the opportunity. It sets a flag onthe opportunity record to true.
A workflow rule looks for records that are created or updated and did not previously met the cobdition where the flag is true then creates an activity assigned to the opportunity.
Since workflow rules fire after APEX code this works just well.