+ Start a Discussion
udayarangareddy mekalaudayarangareddy mekala 

FILE ATTATCHMENT


Hi
VFPAGE
<apex:inputFile filename="{!fileName}"   value="{!resume}"/>
CONTROLLER
public String fileName {get; set;}
public Blob resume {get; set;}
 private Empolyee_Details__c empDetail;

  try{
        if(resume!=null){
        Attachment attach=new Attachment();
        attach.Body=resume;
        attach.Name=filename;
        attach.ParentID=empDetail.id;
        upsert(attach);
        
        
        }
           The above one is the FILE ATTATCHMENT CODE .In that code i didnt get any errors but file was not uploading .please tell me any issues are there for above code.

Thansk&Regards
RangaReddy

Best Answer chosen by udayarangareddy mekala
GauravTrivediGauravTrivedi
You can use the following code 

Visualforce Page
<apex:page controller="attachmentController">
    <apex:form >
        <apex:inputFile value="{!resume}"></apex:inputFile>
        <apex:commandButton value="Submit" action="{!submit}"/>
    </apex:form>
</apex:page>

Apex Class
 
public class attachmentController {
    public blob resume { get; set; }
    public void submit(){
        Attachment att = new Attachment();
        att.Name = 'Resume';
        att.body = resume;
        att.parentId = '0019000000nFfmL';
        try{
            insert att;
        }catch(Exception e){
            system.debug('Oh no there is an exception :  '+e);
        }
    }
}

 

All Answers

GauravTrivediGauravTrivedi
You can use the following code 

Visualforce Page
<apex:page controller="attachmentController">
    <apex:form >
        <apex:inputFile value="{!resume}"></apex:inputFile>
        <apex:commandButton value="Submit" action="{!submit}"/>
    </apex:form>
</apex:page>

Apex Class
 
public class attachmentController {
    public blob resume { get; set; }
    public void submit(){
        Attachment att = new Attachment();
        att.Name = 'Resume';
        att.body = resume;
        att.parentId = '0019000000nFfmL';
        try{
            insert att;
        }catch(Exception e){
            system.debug('Oh no there is an exception :  '+e);
        }
    }
}

 
This was selected as the best answer
GauravTrivediGauravTrivedi
Hey let me know if that works for you.
udayarangareddy mekalaudayarangareddy mekala
Hi
Can u please tell me what is the use of parentid and how to get this id 0019000000nFfmL.

Thanks&Regards
Rangareddy
GauravTrivediGauravTrivedi
Attachment object is always a child of any other object like account, contact, custom object etc. So in parentid you need to pass Id of any parent record, in my example I used account record Id. In your case you are using Employee_Detail__c object, so you need to specify employee record ID with which you want to associate this resume. 
udayarangareddy mekalaudayarangareddy mekala
Thanks Gaurav
The file was uploaded successfully,but it was not showing in the EDIT PAGE.


Thanks&Regards
Ranga
GauravTrivediGauravTrivedi
Where exactly you want, do you want on Standard layout?
SalmanSalman
 Hi  udayarangareddy mekala,

Can you please check this application for Attachments,

MassMailer DOCS let’s you easily mass email email attachments to your leads or contacts while securely storing your files with Rackspace Cloud Files.


You can try this app by installing from appexchange  -Massmailer Docs

You can learn more details about the product on this website - Link