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
karthik selvamkarthik selvam 

Apex Class to export data to local system path

Hi,

i have a trigger for account object (after insert), which will invoke a apex class from which the newly inserted (trigger.new/) data must be exported to my local machine. 
Please guide me

thanks,
Karthik S
Best Answer chosen by karthik selvam
Chris  ByromChris Byrom
That isn't really possible. The problem is you are trying to get the backend of Salesforce to talk directly to your machine, which it can't do. You have a few options to get the data though.
  1. Send it to a web service. If your machine is open to the internet, you could send the data from the trigger to a web service running on your machine. You will have to call an @future method to make the web service call.
  2. Email it. You can have the results emailed to yourself or another account.
  3. You can use a HTTP Callout as well to send the data to specific endpoint.

All Answers

Chris  ByromChris Byrom
That isn't really possible. The problem is you are trying to get the backend of Salesforce to talk directly to your machine, which it can't do. You have a few options to get the data though.
  1. Send it to a web service. If your machine is open to the internet, you could send the data from the trigger to a web service running on your machine. You will have to call an @future method to make the web service call.
  2. Email it. You can have the results emailed to yourself or another account.
  3. You can use a HTTP Callout as well to send the data to specific endpoint.
This was selected as the best answer
Chris  ByromChris Byrom
Also, this article shows a bunch of ways to export data from SF.

https://douglascayers.wordpress.com/2016/03/20/salesforce-easy-ways-to-export-data-as-csv/
karthik selvamkarthik selvam
Hi Chris Byrom,

thanks you for your response i was able to achieve the email method for exporting the data, but can you please guide me through the first method i.e. to invoke a Web Service from salesforce trigger.
Chris  ByromChris Byrom
You can call a Web Service either REST, SOAP, or HTTP Callout from a trigger. You have to put the call in a seperate class and invoke it asynchronously. This means the method has to be annotated with the @Future method. This protects the platform from having long-running external operations during triggers.
karthik selvamkarthik selvam
Hi Chris Byrom,

i was trying the way you guided me ,invoking a @future method in a class by trigger using HTTP callout but i wasn't able to achieve it.
can you please provide me with some code samples, in my scenario i need to send parameter from apex @future class to web service