1

I have a requirement that I have to attach file from local system through local path. Like, I have to upload 'Mobilebills.csv' csv file to document of salesforce through apex code and it will run through trigger. Here I don't have to use VF page to select the file.

How to achieve this ? please help!

  • 1
    not possible...the salesforce server and your local system are in no way connected. – San Tosh Oct 27 '16 at 11:05
  • @SanTosh the requirements are so vague, it's impossible to tell whether this is possible or not. – Nick Cook Oct 27 '16 at 11:37
  • @SanTosh: it is quite possible. Check my answer and also see salesforce file sync client. – Mahmood Oct 28 '16 at 6:46
2

You can use Salesforce Files and then install Salesforce file sync client for your organization. That will allow you to share a local folder on your harddrive be synced with your library folder in your sf org.

Once you have the file in your sf org, with appropriate sharing and visibility rights that is, you can pretty much use it in your custom code (apex, trigger or batch class) for further processing.

Helpful links:

  1. Check Content version.
  2. Content Document link object
  • I have installed the Salesforce file sync client. Now I am able to get the file into salesforce. But this is uploaded into the ContentVersion. How to read from the ContentVersion? There is no body field. – RAHUL SRIVASTAVA Oct 27 '16 at 17:35
  • 1
    You didn't mention anything about accessing the body of the file. Your requirement only stated about getting local file to salesforce and accessing it. Now, related to your query in the comment above - ContentVersion has a field "VersionData" which holds the file in base64 format, similar to body field of attachment object. – Mahmood Oct 27 '16 at 19:31
  • Can we make sync process automate? Now if we upload a file into 'salesforce files' everytime we have to click 'synced' into the files of salesforce. Then we get files into salesforce. Is there any way to schedule this process ? – RAHUL SRIVASTAVA Oct 28 '16 at 11:20
  • @RAHULSRIVASTAVA: you can automate this. First, create a trigger on ContentVersion 'AfterInsert' and then put a new file in your local drive folder. See in the debug log or developer console log to see if it fires the Contentversion - AfterInsert event. If it does, you can write logic in the trigger to perform business process there. 2nd option would be to have a scheduleable batch class, to run on specific times of the day and see if a new file has been added. You could use a custom field for that. One more thing, you said clicking 'synced' would initiate syncing process, syncing is automated – Mahmood Oct 28 '16 at 11:33

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.