2

I'm fairly new to SOQL but I need to write a query that returns all activities (Events and Tasks) that are associated with an opportunity. In addition I'd like to get any campaigns that are influencing the opportunity.

Any help would be appreciated, thanks.

7
  • Any relation between opportunity and Campaign like lookup? Commented Sep 3, 2015 at 21:01
  • @salesforce learner, Not sure if I understand completely but essentially any campaign that has influenced the opportunity that the activity is associated with. Commented Sep 3, 2015 at 21:07
  • SELECT Id, Name,Campaign.Name,Campaign.NumberOfOpportunities,(SELECT Id FROM Tasks), (SELECT Id FROM Events) FROM opportunity WHERE Name = 'Test opp' Commented Sep 3, 2015 at 21:17
  • ERROR: 'No such relation 'Campaign' on entity 'Opportunity'' Commented Sep 3, 2015 at 21:26
  • Can you post the exact query which you tried? Commented Sep 3, 2015 at 21:41

1 Answer 1

1
Select CampaignId, campaign.name, (Select Id From Tasks), (Select Id  From Events) From Opportunity  WHERE id =: oppid

You could quite easily get the SOQL from salesforce schema within eclipse.

2
  • You missed a part of request where OP wants to return the Campaign which influenced the Opportunity as well. Commented Sep 4, 2015 at 0:51
  • Mybad, Updated!
    – cartman
    Commented Sep 4, 2015 at 1:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .