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
Jyosi jyosiJyosi jyosi 

Mutiple contoller in Visualforce page

Hello Everyone,

I have visual force which uses 2 controller extesnion QP_SendRQQCntr &QP_UploadOnBaseDocController
<apex:page standardController="Contact" extensions="QP_SendRQQCntr,QP_UploadOnBaseDocController" >
 <style>
.right
{
  float:right;
  right:0Px;
}
</style>

 <apex:form id="frmId">
  <apex:pageBlock rendered="{!QPRQQ}">
   <apex:pageBlockButtons styleClass="right">
    <apex:commandButton value="Next" action="{!QPRQQNext}" reRender="frmId"/>
   </apex:pageBlockButtons>
   <apex:pageBlockSection columns="1">
    <apex:inputField value="{!ObjContact.Transition_Specialist__c}"/>
    <!--<apex:selectRadio value="{!SelectValue}" label="Is this the correct recruiter?">
    <apex:selectOptions value="{!Recruter}" />
  </apex:selectRadio>-->
   </apex:pageBlockSection>
  </apex:pageBlock>
  <!--
  <apex:pageBlock >
  <apex:pageBlockButtons styleClass="right">
    <apex:commandButton value="Previous" action="{!QPRQQNext}"/>
    <apex:commandButton value="Next" action="{!QPRQQNext}"/>
   </apex:pageBlockButtons>
  <apex:pageBlockSection columns="1">  
   <apex:inputText label="Recruter Name"/>
  </apex:pageBlockSection>
  </apex:pageBlock>
  -->
  <!--                                                       -->
  <apex:pageBlock rendered="{!recruit}">
  <apex:pageBlockButtons styleClass="right">
    <apex:commandButton value="Previous" action="{!previous}" reRender="frmId"/>
    <apex:commandButton value="Next" action="{!recruitInfoNext}" reRender="uploadId,frmId"/>
   </apex:pageBlockButtons>
  <apex:pageBlockSection columns="1">
  <p>Please select the appropriate Prospect Type type from the list provided.<br/></p>
    <apex:inputField value="{!ObjContact.Recruit_type__c}"/>
    Please review the following Prospect information and make any necessary changes.
    <apex:inputField value="{!Contact.CRD__c}"/>
    <apex:inputField value="{!Contact.FirstName}"/>
    <apex:inputField value="{!Contact.Middle_name__c}"/>
    <apex:inputField value="{!Contact.LastName}"/>
    <apex:inputField value="{!Contact.Suffix__c}"/>
    <apex:inputField value="{!Contact.Email}"/>
    <apex:inputField value="{!Contact.MailingStreet}"/>
    <apex:inputField value="{!Contact.MailingCity}"/>
    <apex:inputField value="{!Contact.MailingState}"/>
    <apex:inputField value="{!Contact.mailingpostalCode}"/>
    <apex:inputField value="{!Contact.phone}"/>
    <apex:inputField value="{!Contact.mobilephone}"/>
    </apex:pageBlockSection>
    </apex:pageBlock>
    
 
   <apex:pageBlock rendered="{!recruitConfirm}">
   <apex:pageBlockButtons styleClass="right">
    <apex:commandButton value="Previous" action="{!previous}" reRender="frmId,uploadId"/>
    <apex:commandButton value="Next" action="{!recruitInfoConfirm}" reRender="frmId"/>
   </apex:pageBlockButtons>
   <apex:pageBlockSection columns="1">
    <apex:outputField value="{!Contact.Recruit_type__c}"/>
    <apex:outputField value="{!Contact.CRD__c}"/>
    <apex:outputField value="{!Contact.FirstName}"/>
    <apex:outputField value="{!Contact.phone}"/>
    <apex:outputField value="{!Contact.mobilephone}"/>
    <apex:outputField value="{!Contact.Email}"/>
    <apex:outputField value="{!Contact.MailingStreet}"/>
    <apex:outputField value="{!Contact.MailingCity}"/>
    <apex:outputField value="{!Contact.MailingState}"/>
    <apex:outputField value="{!Contact.mailingpostalCode}"/>
   </apex:pageBlockSection>
   </apex:pageBlock>  
   
    <apex:pageBlock rendered="{!finish}">
    <apex:pageBlockButtons styleClass="right">
    <apex:commandButton value="Finish" action="{!confirmToSend}"/>
   </apex:pageBlockButtons>
    <apex:pageBlockSection >
    <h1>The Registered Rep Qualifying Questionnaire will be sent after clicking Finish.
    Thank you.</h1>
    </apex:pageBlockSection>
    </apex:pageBlock>
 </apex:form>
//THIS PART USES QP_UploadOnBaseDocController  ,but i have selection option on page which it's not pulling the values from second contoller.
 <apex:form id="uploadId" enctype="multipart/form-data">
 <apex:pageBlock rendered="{!uploadBlock}">
  
  <apex:pageBlockButtons styleClass="right">
    <apex:commandButton value="Previous" action="{!previous}" />
    <apex:commandButton value="Next" action="{!uploadNext}" />
   </apex:pageBlockButtons>
   <apex:pageBlockSection columns="1">
  <apex:selectRadio value="{!SelectValue}">
    <apex:actionsupport event="onclick" action="{!fileShowHide}" reRender="frmId,uploadId"/>
    <apex:selectOptions value="{!items}" />
  </apex:selectRadio>
  <br/>
  <apex:outputPanel rendered="{!Display}">
  
   <form enctype="multipart/form-data">
        <apex:pageBlock title="Upload a File" rendered="{!renderUploadForm}">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!uploadDocument}" value="Upload" />
                <apex:commandButton action="{!cancel}" value="Cancel" />
            </apex:pageBlockButtons>

            <apex:pageBlockSection showHeader="false" columns="1" id="block1">

                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Document Type" for="docType"/>
                    <apex:outputPanel styleClass="requiredInput" layout="block">
                        <div class="requiredBlock"></div>
                        <apex:selectList value="{!docType}" id="docType" multiselect="false" size="1">
                            <apex:selectOptions value="{!docTypeOpts}" />
                        </apex:selectList>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="File" for="file" />
                    <apex:outputPanel styleClass="requiredInput" layout="block">
                        <div class="requiredBlock"></div>
                        <apex:inputFile value="{!doc.body}" filename="{!doc.name}" id="file" /> <br />
                        (Allowed file types: {!validFileExtensions})
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
      

        <apex:commandButton action="{!cancel}" value="Back" rendered="{!NOT(renderUploadForm)}" />
    </form>
      </apex:outputPanel>
     
   
   </apex:pageBlockSection> 
  </apex:pageBlock>
  </apex:form>
</apex:page>

First Extension Class

public class QP_SendRQQCntr {

    public String SelectValue{get;set;}
    public Attachment objAttach{get;set;}
    public Boolean Display{get;set;}
    Public Boolean QPRQQ{get;set;}
    public Boolean recruit{get;set;}
    public Boolean uploadBlock{get;set;}
    public Boolean recruitConfirm{get;set;}
    public Boolean finish{get;set;}
    public Contact ObjContact{get;set;}
    public User objUser{get;set;}
    public Boolean renderUploadForm {get; private set;}
    
    public QP_SendRQQCntr(ApexPages.StandardController controller) {
        
        ObjContact=new Contact();
        objAttach=new Attachment(); 
        objUser=new User();
        QPRQQ=true;
        recruit=false;
        uploadBlock=false;
        recruitConfirm=false;
    }
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('SendWithDocuSign','Send With Docusign'));
        options.add(new SelectOption('UplaodFile','Upload a File')); 
        return options; 
    }
    /*public List<SelectOption> getRecruter() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('Yes','Yes'));
        options.add(new SelectOption('No','No')); 
        return options; 
    }*/
    public void previous()
    {
        if(recruit)
        {
            QPRQQ=true;
            recruit=false;
        }
        else if(uploadBlock)
        {
            recruit=true;
            uploadBlock=false;
        }
        else if(recruitConfirm)
        {
            uploadBlock=true;
            recruitConfirm=false;
        }        
    }
     public void QPRQQNext()
    {
        QPRQQ=false;
        recruit=true;
    }
    public void recruitInfoNext()
    {     
        recruit=false;
        uploadBlock=true;
        system.debug('user name---------'+ObjContact.Transition_Specialist__c);
        if(ObjContact.Transition_Specialist__c !=null)
            objUser=[select id,email from user where id =:ObjContact.Transition_Specialist__c];
    }
    public void uploadNext()
    {
        uploadBlock=false;
        recruitConfirm=true;
        
        Blob fileBody = objAttach.body;

        // Create the email attachment
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        efa.setFileName(objAttach.name);
        efa.setBody(fileBody);
        
        String[] toAddresses = new String[] {objUser.email};
        //String toAddresses=''sarvendra;
        
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setSubject( 'Test subject');
        email.setToAddresses(toAddresses);
        email.setPlainTextBody('String'); 
        

        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
        if(fileBody !=null)
        {
        // Sends the email
        Messaging.SendEmailResult [] r = 
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
       
       }
    }
    public void recruitInfoConfirm()
    {
        recruitConfirm=false; 
        finish=true;   
    }
    public void confirmToSend()
    {
    
    }
    public Void fileShowHide()
    {
        if(SelectValue=='UplaodFile')
        {
            Display=true;
            renderUploadForm=true;
            }
        else
            Display=false;
    }
    
}

Second Extension Class

public with sharing class QP_UploadOnBaseDocController {

    public QP_UploadOnBaseDocController(ApexPages.StandardController controller) {

    }


        public String objectName {get; set;}
        public ID recordId {get; set;}

        public Boolean renderUploadForm {get; private set;}
        public Document doc {get; private set;}
        public List<SelectOption> docTypeOpts {get; private set;}

        public String docType {get; set;}

        private String keywordName;
        private String keywordValue;

        public QP_UploadOnBaseDocController() {
                Map<String, String> params = ApexPages.currentPage().getParameters();
                this.objectName = params.get('objectName');
                this.recordId = params.get('recordId');
                this.doc = new Document();
                this.renderUploadForm = true;
                init();
        }

        private void init() {

                try {
                        QP_OnBaseService serv = new QP_OnBaseService();
                        OnBase_Doc_Related_List_Config__c config = serv.getRelatedDocumentsConfig(this.objectName, this.recordId);
                        SObject record = serv.getParentRecord(this.recordId, config);

                        if ( config != null && record != null ) {

                                this.keywordName = config.Keyword_Name__c;
                                this.keywordValue = (String) record.get(config.Keyword_Value_Field__c);

                                if (  this.keywordValue!= null )         {

                                        this.docTypeOpts = new List<SelectOption>{new SelectOption('', '--Select--')};
                                for( String docType : config.Document_Types__c.split(';') ) {
                                    this.docTypeOpts.add(new SelectOption(docType, docType));
                                }
                                } else if ( !ApexPages.hasMessages() ) {
                                        this.renderUploadForm = false;
                                        addMessage(
                                                ApexPages.Severity.ERROR, 'The Keyword field (' + config.Keyword_Value_Field__c + ') is blank.');
                                }
                        } else {
                                this.renderUploadForm = false;
                                addMessage(
                                        ApexPages.Severity.ERROR, 
                                        'Unable to process your request at this time.  Please contact your System Administrator.');
                        }
                } catch(Exception e) {
                        this.renderUploadForm = false;
                        addMessage(
                                ApexPages.Severity.ERROR, 
                                'Unable to process your request at this time.  Please contact your System Administrator.');
                }
        }

        private Boolean validate() {
                Boolean isValid = true;
                if ( this.docType == null || this.docType == '' ) {
                        isValid = false;
                        addMessage(ApexPages.Severity.ERROR, 'Please select Document Type.');
                }
                if ( this.doc == null || this.doc.Body == null ) {
                        isValid = false;
                        addMessage(ApexPages.Severity.ERROR, 'Please select a file to upload.');
                }
                if ( this.doc != null && this.doc.Name != null ) {
                        String[] namePieces = this.doc.Name.split('\\.');
                        System.debug('namePieces: ' + namePieces);
                        String extension = namePieces[namePieces.size() - 1];

                        String fileType = QP_GeneralUtility.getOnBaseFileTypeByExtension(extension);
                        if ( fileType == null ) {
                                isValid = false;
                                addMessage(ApexPages.Severity.ERROR, 'Invalid File Type');
                        }
                }
                return isValid;
        }

        public PageReference uploadDocument() {

                System.debug('doc: ' + this.doc);
                if ( validate() ) {

                        try {
                                IDMServiceDAO dao = new DAOFactory().getIDMServiceDAO();
                                IDMServiceDAO.OnBaseDocument uploadedDoc = 
                                        dao.uploadDocument(this.doc, this.docType, this.keywordName, this.keywordValue);
                                if ( uploadedDoc != null && uploadedDoc.handle != null ) {
                                        addMessage(ApexPages.Severity.CONFIRM, 'Document uploaded successfully.');
                                        this.renderUploadForm = false;
                                } else if ( uploadedDoc != null && uploadedDoc.errorMessage != null ) {
                                        addMessage(
                                                ApexPages.Severity.ERROR, 
                                                'Unable to process your request at this time because of the following error: \n' + uploadedDoc.errorMessage);
                                }
                        } catch (WSCommunicationException e) {
                                addMessage(
                                        ApexPages.Severity.ERROR, 
                                        'Unable to process your request at this time.  Please contact your System Administrator.');
                        }
                }
                this.doc = new Document();
                return null;
        }

        public PageReference cancel() {
                return new PageReference('/' + this.recordId);
        }

        private void addMessage(ApexPages.Severity sev, String msg) {
                ApexPages.addMessage(new ApexPages.Message(sev, msg));
        }

        public String getValidFileExtensions() {
                String validFileExts = String.valueOf(QP_GeneralUtility.getOnBaseValidFileExtensions());
                return validFileExts.length() > 2 ? validFileExts.substring(1, validFileExts.length() - 1) : null;
        }
}

Can you please help me out.

Regards,
Jyo
 
HawkedHawked
help out with ?
Jyosi jyosiJyosi jyosi
I am not able to get the "QP_UploadOnBaseDocController" 
In that method i have Select the Document Type and the file upload to another system.

I am not able to get that methods in Visual force page.

Thanks a lot 

Regards,
Jyo
sandeep sankhlasandeep sankhla
In you class this QP_UploadOnBaseDocController is a constructor not a method...
 
Jyosi jyosiJyosi jyosi
HelloSandeep,

How can i fit this .Could you please help me out.

Regards,
Jyo