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
ChinnoduChinnodu 

apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute.

HI All,

whene ever i am clicking on Attcachfile on VF page i am getting the  below error , Here am attaching with my Class And page.


apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute




PAGE

************************

<apex:page controller="gboCaseController"  sidebar="false" showHeader="false" tabStyle="Coverage_Mapping__c" standardStylesheets="true">
    <!-- EMC Header--> 
    <!--<c:RSA_VF_Header />-->
     <table style="width:100%"> 
     
     <c:CRM_Header_RSA_GBO_webtocase />
     </table>
    <table style="width:100%" align="center">    
        <tr><td>
            <h1><center><b><font size="5">RSA Global Business Operations Case Form</font></b></center></h1>
        </td></tr>
    </table>
    <apex:form >
    <script>
        function colorPageBlock(pageblock, color) 
        {
            if (pageblock != null) pageblock.firstChild.style.cssText = "background-color: " + color + ";";
        }
    </script>
    

    <!--Rajesh: Commenting this table as page messages are showing in 2 places.
    <table width="90%" border="0" style="border-collapse: collapse" bordercolorlight="#808080" id="outerTabel" align="center">    
        <tr>
            
            <font color="#FE000C"><apex:messages /></font>
        </tr>
    </table>  
    -->  
    <apex:pageBlock >
        <apex:pageBlockButtons title="Submit">      
        <!-- Submit Action-->
        <table width="100%" border="0" align="center">
            <tr><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>
            <apex:commandButton value="Submit Case" action="{!submitCase}" id="btn_submit" tabindex="1"/>
            <!-- Added by Kavitha webtocase attachment -- Start --> 
              <!--38th line Commented by viswa-->         
            <!--<apex:commandButton value="Submit Case & Attachment" action="{!submitCaseWithAttachment}" id="btn_submit_attachment" tabindex="1"/>-->           
            <!-- Added by Kavitha webtocase attachment -- End-->            
            </td></tr>
        </table>
        <!-- End of Submit Action-->
        </apex:pageBlockButtons>
        <table width="100%" align="center">
            <tr><td align="center" ><br>
                <h1><b><font size="2" color="#C11B17">SUBMIT NEW CASE</font></b></h1>
            </br></td></tr>         
        </table>  
        <apex:pageMessages />
        <apex:pageBlockSection title="Case Information" columns="2">  
            <apex:pageBlockSectionItem >
                Contact Name <font size="3" color="#C11B17">*</font><apex:inputText value="{!c.SuppliedName}"/>
             </apex:pageBlockSectionItem> 
            <apex:pageBlockSectionItem >
                Company <font size="3" color="#C11B17">*</font><apex:inputText value="{!c.SuppliedCompany}"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                Email <font size="3" color="#C11B17">*</font><apex:inputText value="{!c.SuppliedEmail}"></apex:inputText>       
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                Phone <font size="3" color="#C11B17">*</font><apex:inputText value="{!c.SuppliedPhone}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem rendered="false">
            
                 Record Type <font size="3" color="#C11B17">*</font>
                <apex:outputPanel >
                     <!--<apex:inputtext value="{!c.Record_Type__c}"  />-->
                      <apex:inputField value="{!c.Record_Type__c}" id="recordType"/> 
                      <!--<apex:inputHidden value="{!c.Record_Type__c}" id="recordType"/>                   -->
                                <!--apex:actionSupport event="onchange" rerender="typeList" status="detail"/ -->    
                                <!-- apex:actionStatus id="detail" startText="Requesting..."/ -->                       
                      <!--<apex:selectList value="{!c.Record_Type__c}" size="1" >
                          <apex:selectOption itemLabel="Marketing" itemValue="Marketing"></apex:selectOption>
                      </apex:selectList>-->
                      </apex:outputPanel>
                      </apex:pageBlockSectionItem>
           <apex:pageBlockSectionItem >
               To<font size="3" color="#C11B17">*</font><apex:inputField value="{!c.To__c}"/>
           </apex:pageBlockSectionItem>
           
           <!-- To picklist field ends here-->
          
            <apex:pageBlockSectionItem >
               Country<font size="3" color="#C11B17">*</font><apex:inputField value="{!c.Country__c}"/>
           </apex:pageBlockSectionItem>
           <!-- To picklist field ends here -->
           
           <!-- GBO Type field Added ByVijaykanna -->
           <apex:pageBlockSectionItem >
               GBO Type<font size="3" color="#C11B17">*</font><apex:inputField value="{!c.GBO_Type__c}"/>
           </apex:pageBlockSectionItem>

           <!-- GBO Type field ends here -->
            <apex:pageBlockSectionItem >
               Priority<font size="3" color="#C11B17"></font>
               <!--<apex:inputField value="{!c.Priority}" /> -->
               <apex:selectList value="{!c.Priority}" size="1">
                   <apex:selectOptions value="{!PickLstValue}"></apex:selectOptions>
               </apex:selectList>
           </apex:pageBlockSectionItem>
           
             <!--remove HOT value from priority picklist by viswa >
             
           <!-- To picklist field ends here-->
            
            <!--Added by Vijaykanna-->
           <!--Added by vijaykanna-->
           
           
       </apex:pageBlockSection> 
       <apex:pageBlockSection title="Additional Information" columns="1"> 
           <apex:pageBlockSectionItem >
               Subject <font size="3" color="#C11B17">*</font><apex:inputText value="{!c.Subject}" />
           </apex:pageBlockSectionItem>
           <apex:pageBlockSectionItem >
               Description <font size="3" color="#C11B17">*</font><apex:inputTextarea cols="50" rows="5" value="{!c.Description}"/>
           </apex:pageBlockSectionItem>
       </apex:pageBlockSection>
       
       

       <!--Attachments added section by viswa -->

         <apex:pageBlockSection title="Attachments" columns="1" id="attachSection">
            <apex:outputtext value="Select the File" ></apex:outputtext>
            
            <apex:outputLabel value="Type the path of the file or click the Browse button to find the file."></apex:outputLabel>
            
           <apex:inputFile fileName="{!objCaseAtt.Name}" value="{!objCaseAtt.body}"></apex:inputFile>
           
            <apex:outputtext value="2.Click the Attach File button" ></apex:outputtext>
            <apex:outputLabel value="Repeat steps 1 and 2 to attach multiple files."></apex:outputLabel> 
                      
           
           <apex:outputLabel value="( When the upload is complete the file information will appear below. )"></apex:outputLabel>-->
           
            <apex:commandButton Value="Attach File" action="{!doAttach}" rerender="attachSection"/>                  
             <apex:outputLabel value="3.Click the Done button to return to the previous page."></apex:outputLabel>
            <apex:outputLabel value="( This will cancel an in-progress upload. )"></apex:outputLabel>
            <apex:commandButton Value="Done" action="{!submitCaseWithAttachment}"/>        
              
            </apex:pageBlockSection>
       
       <!--Commented by RaviN WR 199423<apex:pageBlockSection title="Web Description">
           <apex:pageBlockSectionItem >
               Country<font size="3" color="#C11B17">*</font><apex:inputField value="{!c.Country__c}"/>
           </apex:pageBlockSectionItem>
       </apex:pageBlockSection>Commented by RaviN WR 199423-->
       
    </apex:pageBlock>
    <!-- EMC Footer -->
    <c:RSA_VF_Footer ></c:RSA_VF_Footer> 
    </apex:form>
</apex:page>



APEX CLASS

************************************************
public class gboCaseController {
//Public Transient BLOB attachmentBody{get; set;}        
//Public String attachmentName{get; set;}
Public Attachment objCaseAtt {get; set;}
public String caseId{get; set;} 
 
Public List<Attachment> lst_attch{get; set;} 
        
    
    public gboCaseController(ApexPages.StandardController controller) {
       objCaseAtt = new Attachment(); 
    
    caseId = ApexPages.CurrentPage().getParameters().get('id');
    }
    
    public Case c { get; set; }
    
    /*Public string str {get; set;}
public List<SelectOption> getTypeOptions() 
{
List<SelectOption> options = new List<SelectOption>();
String Opt = '';
List<String> strList = new List<String>();
List<Channel_Type__c> listVals = Channel_Type__c.getAll().values();
For(Channel_Type__c ChnlType: listVals )
{
if(ChnlType.Case_Type__c=='Channel')
{
Opt =  ChnlType.Record_Type__c;
strList.Add(Opt);      
}
}
strList.sort();
options.add(new SelectOption('','--None--'));
for(String str : strList)
{
options.add(new SelectOption(str,str));
}
return options;
}*/
    
    //CaseVO caseVO = new CaseVO();
    
    //  public CaseRecordType caseRecordType ;
    //   
    /*  public void setCaseVO (CaseVO caseVO ) 
{
caseVO = caseVO;
}
public CaseVO getCaseVO () 
{
return caseVO ;
}   */
    
    public gboCaseController() {
        //c = new Case(RecordTypeId = '012560000000DrN');
        Id recTypeId = [Select Id, Name from RecordType where Name = 'GBOCase'][0].Id;
        c = new Case(RecordTypeId = recTypeId);
        //c.Record_Type__C = 'GBOcase';
      
        
    }
    public PageReference submitCase() {
        boolean isMandatoryFailed = false;
        if(c.SuppliedName== null || c.SuppliedName==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Contact Name'));
            isMandatoryFailed = true;   
            
        }
        if(c.SuppliedCompany== null || c.SuppliedCompany==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Company'));   
            isMandatoryFailed = true;   
            
        }
        if(c.SuppliedEmail== null || c.SuppliedEmail=='' ){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Email'));   
            isMandatoryFailed = true;   
            
        }
        if(c.suppliedEmail.contains('@gmail.com')|| c.suppliedEmail.contains('@yahoo.com')|| c.suppliedEmail.contains('@hotmail.com')){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please enter valid business email'));   
            isMandatoryFailed = true;   
            
        }
        if(c.SuppliedPhone== null || c.SuppliedPhone==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Phone'));   
            isMandatoryFailed = true;   
            
        }
        if(c.To__c== null || c.To__c==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please pick up a value from To'));   
            isMandatoryFailed = true;   
        }
        
        if(c.GBO_Type__c== null || c.GBO_Type__c==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please pick up a value from GBOType'));   
            isMandatoryFailed = true;   
        }
        if(c.Subject== null || c.Subject==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Subject'));   
            isMandatoryFailed = true;
        }
        if(c.Description== null || c.Description==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Description'));   
            isMandatoryFailed = true;
        }
        if(c.Country__c== null || c.Country__c==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Country'));   
            isMandatoryFailed = true;
        }
        
        if(isMandatoryFailed){
            return null;
        }
        List<String> contList = new List<String>(); 
        try {
            Integer i=0;        
            // now look for an associated contact with the same email
            for(Contact cnt : [SELECT Id,Email FROM Contact WHERE Email = :c.SuppliedEmail]){
                if (cnt != null) {
                    contList.add(cnt.Id);
                    i++;
                }
            }
            If(contList!=null){
                if(i<1){
                    
                }else if(i>1){
                    
                }else if (i==1){
                    for(String contStr :contList)
                    {
                        c.ContactId=contStr;
                    }
                    
                }
            }
            
            
            // c.RecordTypeId=c.Record_Type__c;
            // Specify DML options to ensure the assignment rules are executed
            Database.DMLOptions dmlOpts = new Database.DMLOptions();
            dmlOpts.assignmentRuleHeader.useDefaultRule = true;
            c.setOptions(dmlOpts);
            c.Is_Submitted_From_Site__c = true;
            c.IsVisibleInSelfService = False; 
            // Insert the case
            INSERT c;
            PageReference redirectPage= new PageReference('https://www.rsa.com');
            return redirectPage;//new PageReference('/thanks');
        } catch (Exception e) {
            ApexPages.addMessages(e);
            System.debug('Exception in gboCaseController: '+e);
            return null;
        }
    }
    public PageReference submitCaseWithAttachment() {
        
        boolean isMandatoryFailed = false;
        if(c.SuppliedName== null || c.SuppliedName==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Contact Name'));
            isMandatoryFailed = true;   
            
        }
        if(c.SuppliedCompany== null || c.SuppliedCompany==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Company'));   
            isMandatoryFailed = true;   
            
        }
        if(c.SuppliedEmail== null || c.SuppliedEmail==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Email'));   
            isMandatoryFailed = true;   
            
        }
        if(c.suppliedEmail.contains('@gmail.com')|| c.suppliedEmail.contains('@yahoo.com')|| c.suppliedEmail.contains('@hotmail.com')){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please enter valid business email'));   
            isMandatoryFailed = true;   
            
        }
        if(c.SuppliedPhone== null || c.SuppliedPhone==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Phone'));   
            isMandatoryFailed = true;   
            
        }
        if(c.To__c== null || c.To__c==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please pick up a value from To'));   
            isMandatoryFailed = true;   
        }
        if(c.GBO_Type__c== null || c.GBO_Type__c==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please pick up a value from GBOType'));   
            isMandatoryFailed = true;   
        }
        if(c.Subject== null || c.Subject==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Subject'));   
            isMandatoryFailed = true;
        }
        if(c.Description== null || c.Description==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Description'));   
            isMandatoryFailed = true;
        }
        if(c.Country__c== null || c.Country__c==''){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please Enter Country'));   
            isMandatoryFailed = true;
        }
        
        if(isMandatoryFailed){
            return null;
        }
        List<String> contList = new List<String>(); 
        try {
            Integer i=0;        
            // now look for an associated contact with the same email
            for(Contact cnt : [SELECT Id,Email FROM Contact WHERE Email = :c.SuppliedEmail]){
                if (cnt != null) {
                    contList.add(cnt.Id);
                    i++;
                }
            }
            If(contList!=null){
                if(i<1){
                    
                }else if(i>1){
                    
                }else if (i==1){
                    for(String contStr :contList)
                    {
                        c.ContactId=contStr;
                    }
                    
                }
            }
            //   c.Type=CaseVO.getType();
            
            // c.RecordTypeId=c.Record_Type__c;
            // Specify DML options to ensure the assignment rules are executed
            Database.DMLOptions dmlOpts = new Database.DMLOptions();
            dmlOpts.assignmentRuleHeader.useDefaultRule = true;
            c.setOptions(dmlOpts);
            c.Is_Submitted_From_Site__c = true;
            // Insert the case
            // INSERT c;
            // Added by Kavitha - Webtocase Attachment - Start               
            Database.SaveResult res = Database.Insert(c,false);
            System.debug('gboCaseController Error: '+res.getErrors());
            PageReference redirectAttachmentPage;
            if(res.getId()!= null)
            {
                case cs = [select id,CaseNumber from case where id =:res.getId()];
                redirectAttachmentPage= new PageReference('/apex/SubmitCaseAttachmentPage?id='+res.getId());
                // redirectAttachmentPage= new PageReference('http://sit-rsa.cs1.force.com/webtocase/p/attach/NoteAttach?pid='+cs.id+'&parentname='+cs.casenumber);
                redirectAttachmentPage.setRedirect(TRUE);
                return redirectAttachmentPage;//new PageReference('/thanks');
            }else
            {
                String strError; 
                for(Database.Error err : res.getErrors()) 
                {
                    strError += err+ ';';
                }
                
                return null;
                
            }
        } catch (Exception e) {
            ApexPages.addMessages(e);
            return null;
        }
    }
    
    //added by viswa from 271 line to 297 line
    
    public List<SelectOption> getPickLstValue()

    {

    List<SelectOption> options = new List<SelectOption>();

     Schema.DescribeFieldResult fieldResult = Case.Priority.getDescribe();

    List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

    for(Schema.PicklistEntry f : ple)

    {

     if(f.getValue() != 'Hot')

     {

   options.add(new SelectOption(f.getLabel(), f.getValue()));

   }

     }  

           return options;            

  }

    
    public void doAttach()
     {

        String caseid1 = ApexPages.CurrentPage().getParameters().get('id');     
        
        if(objCaseAtt.Name != null && objCaseAtt.Name !='' )        
        { 
              
          objCaseAtt.ParentId = caseId;  
            try{             
          insert(objCaseAtt); 
          }
          catch(exception e){
          ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error: Please specify a file to upload. Type in the path to the file, or use the "Browse" button to locate it in your local filesystem.'));
          }
          finally{
         objCaseAtt = new attachment();
         
          } 
          
      /*  Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        efa.setFileName(attachmentName);
        efa.setContentType('application/Pdf');
        efa.setBody(attachmentBody);  
        system.debug('Test---90>>>'+attachmentBody.size());
       // if(attachmentBody.size()<156000) {          
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setUseSignature(false);
        mail.setToAddresses( new String[] {System.Label.webtocaseattachinsert});
     //  mail.setToAddresses('udaykumar.pathi@rsa.com');
        mail.setSubject(caseId);
        mail.setPlainTextBody('case attachment');
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] { efa }); 
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });*/
      //  }
       /* else{
         ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error: Size of the file cannot be greater than 150KB.'));*/     

       //}
            lst_attch = new List<attachment>();
            lst_attch = [Select id,name,Parent.name from attachment where parentid =:caseid];
          }
		 else        
		{
			  ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error: Please specify a file to upload. Type in the path to the file, or use the "Browse" button to locate it in your local filesystem.'));
		}
        }
    
}

Thanks,
Viswaeshrao

 
SandhyaSandhya (Salesforce Developers) 
Hi Viswa,

After some research, I found that you cannot use apex:inputFile and action component, apex:commandButton or apex:commandLink together.To exceed this limitation, you need to wrap the command button in apex:actionregion.


Please refer below which has the similar discussion.


http://salesforce.stackexchange.com/questions/16635/apexinputfile-cannot-be-used-with-that-specifies-a-rerender-or-oncomplet/16636#16636
 
https://developer.salesforce.com/forums/?id=906F000000096MRIAY
 
http://salesforce.stackexchange.com/questions/34426/apexinputfile-cant-be-used-in-conjunction-with-an-action-component-issues

 And also there is a solution for this using HTML,please refer below link for the same.


http://manojjena20.blogspot.sg/2015/11/apexinputfile-can-not-be-used-in.html
  
Hope this helps you!

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya

 
Braj Mohan Prasad SinhaBraj Mohan Prasad Sinha
Its working for me. Thanks.