I am using model window VF page to add attachments in another Vf(Main) page. Attachments is getting added to the case. once the attachment is added, the entire page is redirect to Modal window page(Refreshes), Its not staying in main page.

Javascript code in Main VF page:

 $scope.getAttach = function(sNORId, sCaseId, sRequestFrom) {

                var baseUrlLink = $scope.getBaseURL();
                    modal: true,
                    open: function ()
                    close: function (e) {
                    height: 400,
                    width: 400,
                    title: 'Add Attachments'

Modal Window VF page:

<apex:page controller="Rforce_GetAttachmentTypes_CTR" showHeader="false" sidebar="false" standardStylesheets="false">
    <apex:form >
        <apex:pageBlock >
            <apex:repeat value="{!Attachments}" var="a" rendered="{!Attachments.size>0}">
                <apex:inputFile value="{!a.oAttachment.body}" filename="{!a.oAttachment.name}" id="file1"/>
            <apex:commandButton value="Upload" action="{!uploadAttachments}"/>


Controller for model window:

public class Rforce_GetAttachmentTypes_CTR {
    public List<attachmentTypes> lAttachmentType{get;set;}
    public string sNaofReId = ApexPages.currentPage().getParameters().get('nId');
    public string caseId = ApexPages.currentPage().getParameters().get('csId');
    public string requestName = ApexPages.currentPage().getParameters().get('reqName');
    public Rforce_GetAttachmentTypes_CTR(){        
  //Getting List of attachments types 
    public List<attachmentTypes> getAttachments(){
        lAttachmentType = new List<attachmentTypes>();
            NAT_Request__c oNaOfRe = [Select id,(select id,Name,Mandatory__c from Attachments_Linkeds__r) 
                                      FROM NAT_Request__c Where Id=:sNaofReId];
                for(Integer i=0 ;i<oNaOfRe.Attachments_Linkeds__r.size();i++){
                    lAttachmentType.add(new attachmentTypes(new attachment(),oNaOfRe.Attachments_Linkeds__r[i])); 
            lAttachmentType.add(new attachmentTypes(new attachment(),new ATT_Linked__c()));
        return lAttachmentType;
  //inseting attachments for a case
    public void uploadAttachments(){
        List<Attachment> lAttachments = new List<Attachment>();
        for(attachmentTypes atTypes : lAttachmentType){
            if(atTypes.oAttachment.Body!=null && !String.isBlank(atTypes.oAttachment.name)){
                atTypes.oAttachment.ParentId= caseId; 
                if(requestName == 'finance') {
                    atTypes.oAttachment.Description= 'custinfoattachment';
                }else {
                    atTypes.oAttachment.Description= 'fininfoattachment';

            }catch(Exception e){
                system.debug('Unable to insert Attachments'+e);
  //Wrapper Class to get attachment and attachment name  
    public class attachmentTypes{
        public ATT_Linked__c oATTLinked{get;set;}
        public Attachment oAttachment{get;set;}
        public attachmentTypes(Attachment oAtt,ATT_Linked__c oAttLink){

Before Upload button is clicked in Modal Window : enter image description here

After Upload button is clicked in Modal Window : enter image description here


The apex:commandButton by default will reload the whole page after the user clicks on it. If you want to workaround it - add a reRender attribute to the button:

<apex:commandButton value="Upload" 
  • I am not using apex tags for upload button. I am using HTML tags i tried in that <button reRender="none" ng-click="getAttach('',caseIdInfo)" id="fileUploadId">. Its not working . – Sathish Aug 12 '16 at 8:20
  • @Sathish So you have posted a wrong code? – Sergej Utko Aug 12 '16 at 8:55
  • I am sorry . I have tried with your answer. Its not working. – Sathish Aug 12 '16 at 10:36

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.