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
Priya MishraPriya Mishra 

common controller for three different vf pages

I have 3 diffrent visualforce pages and one common controler for the vf pages. my senario is:
upload document is the required field in two forms but i want only in one form it shoul be mandatory and in other form it should not be how can i achieve this.

thanks in advance.
Raj VakatiRaj Vakati
You can use conditional rendering and display the data based on it .. 

Or you can do one more think .. ( Move the all common code into utility class and call them into the three different controllers)


 
Priya MishraPriya Mishra
Actully this is the controller which i am using for three of the forms:

so below bold SaveRequest() method is runnig while clicking on the submit button i want this document size check work for one page and not for other page.


Public class SFDC_Access_Controller extends SitesTodHeaderController{

public Case_form_extension_two__c ObjRMS {get;set;}
public string efileName {get;set;}// holds the email attachment name 
public transient Blob efileBody {get;set;}// holds the email attachment body
 public string datevalue{get;set;}
 public Case casvar {set;get;}
public Case Parent_Case{set;get;}
public String SFDC_Form_Value {get;set;}
public List<SelectOption> SFDC_Form_Options {get;set;}
public GBL_Attachments attachmentHelper{get; set;}
public List<String> docIdList = new List<string>();
public boolean pageError {get;set;}
public String pageErrorMessage {get;set;}
public String FormType {get;set;}

    public SFDC_Access_Controller(){
            SFDC_Form_Options_Config();
            casvar =new Case();
            attachmentHelper = new GBL_Attachments();
            ObjRMS = new Case_form_extension_two__c();
            FormType = apexpages.currentPage().getParameters().get('FormType');
            
    
    }

   public PageReference next(){
   
               if(SFDC_Form_Value =='Null'){
               
                   Apexpages.addMessage( new ApexPages.Message (ApexPages.Severity.ERROR, 'Please select Type of request'));     
               }
               
               if(SFDC_Form_Value == 'SFDC Access'){
                   
                       PageReference pageRef = new PageReference('/apex/SF_Access_Form?FormType='+SFDC_Form_Value);
                       pageRef.setRedirect(true);
                       return pageRef;
     
               } 
               
                if(SFDC_Form_Value == 'Activate Interviewer'){
                   
                       PageReference pageRef = new PageReference('/apex/Activate_Interviewer_Form?FormType='+SFDC_Form_Value);
                       pageRef.setRedirect(true);
                       return pageRef;
     
               } 
               
   
   return null;
   }
   
   public PageReference SaveRequest(){
            

            
            if(attachmentHelper.UploadedDocumentList.size()==0){
               system.debug('attachmentHelper.UploadedDocumentList---' + attachmentHelper.UploadedDocumentList );
                    Apexpages.addMessage( new ApexPages.Message (ApexPages.Severity.ERROR, 'Please upload documents'));  
                     
            }        
            if(attachmentHelper.UploadedDocumentList.size()>0){
            

            System.debug('FormType---' + FormType);
            Schema.DescribeSObjectResult d = Schema.SObjectType.Case; 
            Map<String,Schema.RecordTypeInfo> rtMapByName = d.getRecordTypeInfosByName();
            Schema.RecordTypeInfo rtByName =  rtMapByName.get('Case');
            System.debug('rtByName---'+rtByName);
            String caseid = rtByName.getRecordTypeId();
            System.debug('caseid---'+caseid);
            
            Schema.DescribeSObjectResult SFAccess_d = Schema.SObjectType.Case_form_extension_two__c; 
            Map<String,Schema.RecordTypeInfo> SFAccess_rtMapByName = SFAccess_d.getRecordTypeInfosByName();
            Schema.RecordTypeInfo SFAccess_rtByName =  SFAccess_rtMapByName.get('SF Access');
            System.debug('SFAccess_rtByName---'+SFAccess_rtByName);
            String SFAccesscaseformexc2id = SFAccess_rtByName.getRecordTypeId();
            Schema.DescribeSObjectResult ActivateInterviewer_d = Schema.SObjectType.Case_form_extension_two__c; 
            Map<String,Schema.RecordTypeInfo> ActivateInterviewer_rtMapByName = ActivateInterviewer_d.getRecordTypeInfosByName();
            Schema.RecordTypeInfo ActivateInterviewer_rtByName =  ActivateInterviewer_rtMapByName.get('Activate Interviewer');
            System.debug('ActivateInterviewer_rtByName---'+ActivateInterviewer_rtByName);
            String ActivateInterviewer_caseformexc2id = ActivateInterviewer_rtByName.getRecordTypeId();
            
            
   
            Case casvar = new Case();
            
                casvar.Status = 'New';
                casvar.Origin = 'Web';
                casvar.ContactId = loggedInContact.id;
                casvar.WCT_ReportedBy__c = loggedInContact.id;
                casvar.Priority = '3 - Medium';
                casvar.WCT_Category__c = 'Technology';
                if(FormType == 'SFDC Access'){
                casvar.WCT_SubCategory1__c = 'Salesforce';
                casvar.WCT_SubCategory2__c = 'SFDC Access';
                casvar.subject ='SFDC Access';
                casvar.description = 'SFDC Access';
                }
                if(FormType == 'Activate Interviewer'){
                casvar.WCT_SubCategory1__c = 'Salesforce';
                casvar.WCT_SubCategory2__c = 'Activate Interviewer';
                casvar.subject ='Activate Interviewer';
                casvar.description = 'Activate Interviewer';
                }
                
              
                system.debug('casvar---' + casvar);
                system.debug('SFDC_Form_Value ---' + SFDC_Form_Value );
                
                Database.DMLOptions dmlOpts = new Database.DMLOptions();
                dmlOpts.assignmentRuleHeader.assignmentRuleId= Label.Case_Assignment_Rule_Id ;
                dmlOpts.EmailHeader.TriggerUserEmail = true;
                casvar.setOptions(dmlOpts);                                                     
                insert casvar;       
                
                Case ParentCase= new Case();
                
                ParentCase = [Select id,CaseNumber from Case where id=:casvar.id];
                
               if(FormType == 'SFDC Access'){
            
                    ObjRMS.RecordtypeId = SFAccesscaseformexc2id;
                    ObjRMS.Case_CFE2__c = casvar.id;
                    insert  ObjRMS;
               
               }
               if(FormType == 'Activate Interviewer'){
            
                    ObjRMS.RecordtypeId = ActivateInterviewer_caseformexc2id;
                    ObjRMS.Case_CFE2__c = casvar.id;
                    insert  ObjRMS;
               
               }
                   
                  attachmentHelper.uploadRelatedAttachment(casvar.Id);
                
               PageReference pr = new PageReference('/apex/GBL_Page_Notification?key=SFDC_request&label=HOME&url=/apex/SFDC_request_Home_Form&casenum='+ParentCase.CaseNumber);  // redirects to the thank you page
                pr.setRedirect(true);  
                return pr; 
    
   }
   else{
    Apexpages.addMessage( new ApexPages.Message (ApexPages.Severity.ERROR, 'Please upload documents')); 
  

  }
  return null;
   }

 
   public void SFDC_Form_Options_Config(){
           
           SFDC_Form_Options  = new List<SelectOption>();
           
           SFDC_Form_Options.add(new SelectOption('Null','--None--'));
           SFDC_Form_Options.add(new SelectOption('SFDC Access','SFDC Access'));
           SFDC_Form_Options.add(new SelectOption('Activate Interviewer','Activate Interviewer'));
           
           
     }


}