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
Bethann GonzalezBethann Gonzalez 

How would I create a "attachment button" using Apex Code?

I would like to attach a document to an Calendar event. In order to do, I am assuming I have to create a new button.  What should I select for th content source? "Onclick javascript" or "visual page". Which is easier to accomplish? In addition I am not sure what the javascript would be in order to generate this button. Please help. 

sandeep@Salesforcesandeep@Salesforce

You can do this in 2 ways using HTML button or Apex:commadbutton here you need to bind two property fileName and FileContent wth VF page.

<apex:inputFile value="{!test}" filename="{!fileName}" />

<apex:commandButton action="{!Uploadfile}" value="Upload File" id="theButton"  />

 

in controller you need to Keep these two properties : 

test{get;set;}

fileName{get;set;}

 

sushant sussushant sus

in page:

 

<apex:inputFile value="{!photo}"> </apex:inputFile>
                              <apex:commandButton value="Upload photo" action="{!uploadphoto}" />

 

controller:

 Attachment objA=new Attachment();
            objA.body = photo;
            objA.name = 'testname';
            objA.parentid= event.id;
        
            insert objA;

Please Mark this as solution (if it was helpful) to make it available to others for similar problem & Don't forget to give me KUDOS by Clicking on STAR icon

 

sushant