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
marys pindamarys pinda 

Computer file to Salesforce

Hello,
Is it possible to develop an Apex class that will take a file on my computer EVERY DAY and it will stored in Salesforce?
How do I do this?
Does anyone have any code for me to follow as a model?

Thank you,
Karan Khanna 6Karan Khanna 6
Hi,

I dont think you can do that through Apex, why dont you go other way round, push the file from your desktop to Salesforce.

simplest way which I can think to achieve this would be:


1. Create inbound email service handler in salesforce to handle incoming mails (along with attachments). here you can find sample code:
https://developer.salesforce.com/page/An_Introduction_To_Email_Services_on_Force.com

2. Create a task on your desktop through Control panel for sending that file to salesforce email service handler address through mail.
Open Task Scheduler by clicking the Start button   , clicking “Control Panel”, clicking “System and Security”, clicking “Administrative Tools”.

marys pindamarys pinda
Thank you...

The Apex is not able to manipulate a file from my computer and send to the Salesforce platform?
marys pindamarys pinda
I managed to make a code to send any file to Salesforce.

<apex:page controller="UploadDoc">
<apex:form >
  <apex:sectionHeader title="Upload a Document into Salesforce"/>
  <apex:pageblock >
      <apex:pageblocksection columns="1">
          <apex:inputfile value="{!myimage.body}" filename="{!myimage.Name}" />
          <apex:commandbutton value="Save" action="{!Savedoc}"/>
      </apex:pageblocksection>
  </apex:pageblock>   
</apex:form> 
</apex:page>

--------------------------------------------------------------------------------------------------

public class UploadDoc
{
Public Document mydoc;
    Public Document getmyimage()
    {
        mydoc = new Document();
        return mydoc;
    }
   
    Public Pagereference Savedoc()
    {
        mydoc.folderid = UserInfo.getUserId(); 
        insert mydoc;
        return NULL;
    }        
}


Now I wonder how it is possible to upload a single file.
I do not want to give the option to search for the file I want the Apex class to run automatically (schedulable) to upload the specified file.
How do I do this?

Thank you,
Karan Khanna 6Karan Khanna 6
The approach you are taking requires manual efforts, someone has to open that VFPage and manually upload a file, I am afraid it can't be automated.
marys pindamarys pinda
Thank you!