You need to sign in to do that
Don't have an account?
Bethann 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.
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;}
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