1

For a non-Apex app (web REST API only), how can I consolidate these requests:

  1. find all contacts that match an email address
  2. find all opportunities associated with those contacts from 1

Right now, I have these as 2 separate requests. I'd like to consolidate them into one. Is that possible? If so, how?

3

Assuming that the junction between Contact and Opportunity is via the OpportunityContactRole object, then the answer is yes, with caveats. You would need to run a query on the OCR object to return all related fields on Opportunity and Contact, so your REST call would look something like this:

/services/data/v32.0/query/?q=SELECT+Opportunity.Field__c,+Contact.Field__c+FROM+OpportunityContactRole+WHERE+Primary+=+TRUE+AND+Contact.Email+=+MY_EMAIL

Now the caveats... this isn't quite what you asked for in #1 & 2 but it's close. This query returns a list of contacts that have opportunities (inner join), in which that contact is the primary opportunity contact role and matches that email address. The list returned may represent many different contacts and many different opportunities, which you'd then have to parse in your app.

Another great alternative is an Apex REST Service, which will return whatever you want. This allows you to develop your API and maintain your logic in Salesforce instead of your external app. Take a look at Apex REST Services Overview for more information.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.