function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lauren HonyotskiLauren Honyotski 

Pass Salesforce data field to external database

I have a requirement to pass a date field to an external database when this date field changes. What would be the easiest way to accomplish this?
Best Answer chosen by Lauren Honyotski
Krishna SambarajuKrishna Sambaraju
I am not sure how familiar you are with the apex and visualforce. Here is an example of sending a request to an end point using HttpRequest.
HttpRequest request = new HttpRequest();
request.setTimeout(60000);
request.setMethod('POST');
request.setEndpoint(your_end_point_goes_here);
request.setHeader('Content-Type', 'application/x-www-form-urlencoded');

request.setBody(Your_body_goes_here_in_the_format_required_by_REST_Call);
HttpResponse response = new Http().send(request);
Here is a link for a complete example
http://blog.jeffdouglas.com/2009/03/16/restful-web-service-callout-using-post/

Change the end points and objects and fields according to your requirement.

Hope this helps.

All Answers

Krishna SambarajuKrishna Sambaraju
Create a worlflow rule that tracks the change of this field. Add an Outbound Message workflow action which points to an external webservice. Pass the data to this external webservice which updates the External Database.
Lauren HonyotskiLauren Honyotski
Thanks Krishna. That would be the easiest. I now know the site I need to transmit data to will not accept SOAP calls. But the developer on the team can create a REST endpoint. REST API seems a lot more complex. Any suggestions where to start? Thanks!
Krishna SambarajuKrishna Sambaraju
I am not sure how familiar you are with the apex and visualforce. Here is an example of sending a request to an end point using HttpRequest.
HttpRequest request = new HttpRequest();
request.setTimeout(60000);
request.setMethod('POST');
request.setEndpoint(your_end_point_goes_here);
request.setHeader('Content-Type', 'application/x-www-form-urlencoded');

request.setBody(Your_body_goes_here_in_the_format_required_by_REST_Call);
HttpResponse response = new Http().send(request);
Here is a link for a complete example
http://blog.jeffdouglas.com/2009/03/16/restful-web-service-callout-using-post/

Change the end points and objects and fields according to your requirement.

Hope this helps.
This was selected as the best answer
Lauren HonyotskiLauren Honyotski
Thank you, this is very helpful.