+ Start a Discussion
Alaric WimerAlaric Wimer 

How to query all a list of Opportunities that are counted in the Campaign record's "Opportunities in Campaign" field?

I have a Campaign called "My Campaign" where I can see the "Opportunities in Campaign" field. It has a value of 41. However, when I try to query a list of these Opportunities with the following query (see below) I get 0 records found. Does anyone how I can query these Opportunities?

What I'm ultimately trying to do is create a field on the Campaign (using a trigger) that shows how many Opportunities are in a particular stage. So, I'd like to know how to query and filter these Opportunities that make up this count.

SOQL query that returned 0 records:

SELECT Id, Campaign.Name
   FROM Opportunity
WHERE Campaign.Name = 'My Campaign'
GauravGargGauravGarg
Hi Alaric,

Can you try using %% and Like like below:
SELECT Id, Campaign.Name
FROM Opportunity
WHERE Campaign.Name LIKE '%MY Campaign%'


OR

SELECT Id, Campaign.Name
FROM Opportunity
WHERE Campaign.Name LIKE '%MY%Campaign%'

Hope this provides some query results. Also, if possible can you share one Opportunity record details i.e. name, campaign name to look more into the issue if un-resolved. 

Thanks,
Gaurav
Skype: gaurav62990
Alaric WimerAlaric Wimer

Thank you Gaurav, unfortunately I've already tried the LIKE filter with no results.

 

However, I've noticed that the Opportunities appear in the Campaign's "Influenced Opportunities" related list. So another way to think of what I need is how can I query the "Influenced Opportunities" related list on the Campaign?

Alaric WimerAlaric Wimer

Do you know how I can get the COUNT(Id) of each Campaign into a variable so I can set it to the Opportunity by stage field on the Campaign object that I want to create? The query I used from that link was:

 

SELECT Campaign.Name, Campaign.NumberOfOpportunities, COUNT(Id)
FROM Opportunity
WHERE CampaignId != null AND CloseDate = THIS_MONTH
GROUP BY Campaign.Name, Campaign.NumberOfOpportunities