You need to sign in to do that
Don't have an account?
moorecats
Using a trigger to send a post to a REST API when a new opportunity is created
Hi
I am just starting with Force.com and Apex etc. My goal is simply to call a REST API with the details of a new opportunity. Is the best way to do this via Apex or is there another approach. I am simply looking for some guidance to make sure I am not going down a long rabbit hole for something that can be done another way. Any advice is appreciated!
Thank You
If it must be REST, then you will need a trigger. The general flow will be like this:
Trigger on Opportunity (after insert) -> Asynchronous function call (@future annotation) -> HttpRequest/HttpResponse -> (Optional) Update Opportunity data.
If you can use SOAP notifications, you can just visit Setup > Create > Workflow & Approvals > Workflow Rules/Outbound Messages (you'll need one of each). This is a built-in way to send notifications to external systems without writing code in salesforce.com at all (you'll need a SOAP endpoint configured with the WSDL from the Outbound Message, though). It might be easier to take this route in terms of development time, if you or someone you know is more competent in PHP, .NET, etc than in Apex Code.
All Answers
If it must be REST, then you will need a trigger. The general flow will be like this:
Trigger on Opportunity (after insert) -> Asynchronous function call (@future annotation) -> HttpRequest/HttpResponse -> (Optional) Update Opportunity data.
If you can use SOAP notifications, you can just visit Setup > Create > Workflow & Approvals > Workflow Rules/Outbound Messages (you'll need one of each). This is a built-in way to send notifications to external systems without writing code in salesforce.com at all (you'll need a SOAP endpoint configured with the WSDL from the Outbound Message, though). It might be easier to take this route in terms of development time, if you or someone you know is more competent in PHP, .NET, etc than in Apex Code.
Thanks for the info, in my research I also ran into this - http://www.salesforce.com/us/developer/docs/api_streaming/index.htm
What are your views about this API?
moorecats, based on your original post, I would have to assume this is not the API you are looking for. The reason why is because it is designed to be a lightweight mechanism for "clients" to receive interesting updates, rather than pushing notifications to other servers. A good use example would be a "ticker" type display that shows large opportunities to interested parties in realtime (e.g. the VP of Sales that uses salesforce.com might want to see new opportunities over $1,000,000). If your goal is data replication for other purposes, consider Outbound Messages, REST or SOAP asynchronous notifications, or you might simply choose to create an external integration that uses hourly polling to take advantage of salesforce.com's replication API, which is a subset of their SOAP API that is designed to provide data to keep external systems synchronized with salesforce.com (via getDeleted and getUpdated). Feel free to provide some more information on what your task and current situation is, and perhaps we can be of more help.
Thank you for the explanation!