I created a VF page which is used for uploading files on Account object. I was able to successfully upload the files on Mobile, but the problem is not able to give success or error message after uploading a file.

Can anyone please help me with this ? I am trying this on salesforce1

Visualforce :

 <apex:page standardController="Account" extensions="mobileAttachment">
<h1><b> <p style="font-size:20px"> Attach File to Account {!Account.Name} </p></b></h1>
<apex:form >
<apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}" />
<apex:commandbutton value="Save" action="{!Savedoc}"/>

Controller :

public class mobileAttachment {

    public mobileAttachment(ApexPages.StandardController controller) {

    Public Attachment myfile;
    Public Attachment getmyfile()
        myfile = new Attachment();
        return myfile;

    Public Pagereference Savedoc()
        String accid = System.currentPagereference().getParameters().get('id');

        Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body);

         /* insert the attachment */
         try {
         insert a;

          ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
         catch (DMLException e) {
          ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
          return null;


        return NULL;


You need to include

<apex:pageMessages />

in your VF-Page so that it knows where to show the message.

| improve this answer | |

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.