+ Start a Discussion
Bob_zBob_z 

Combine two apex class

Is there a way to combine both these classes(Account & Case)  into one so i there isn't two seperate classes in my org? I'm not sure how to accimplish this and could use help.

Account class
Public Class VF_SiteServicePartnerAllController{
   private Account acc;
   public List<Site_Service_Partner__c> sspList {get;set;}
   
   public VF_SiteServicePartnerAllController(ApexPages.StandardController sp){
       acc = (Account)sp.getRecord();
       sspList = new List<Site_Service_Partner__c>();
       sspList = [SELECT Id,Name,Site_Account__c,Primary_Field_Contact__c,Service_Partner__c,
                  Service_Partner_Owner__c,Service_Partner_Owner_Mobile__c,Service_Partner_Owner_Email__c,
                  Primary_Field_Email__c,Primary_Field_Mobile__c,Service_Partner_Site_Status__c, 
                  Contracted_Services__c,Secondary_Field_Contact__c,Secondary_Field_Email__c,Secondary_Field_Mobile__c,
                  Service_Partner_Start_Date__c,Service_Partner_End_Date__c,Service_Partner_Main_Phone__c,Trade__c,Supported_Trade__c,trade_value__c  FROM Site_Service_Partner__c WHERE Site_Account__c =: acc.Id    AND  Trade__c IN ('Land', 'Snow', 'Land;Snow') AND Service_Partner_Site_Status__c = 'Active'];

    
    Set<Id> bidId = new  Set<Id>();  
    for(Site_Service_Partner__c bs:sspList){
       bidId.add(bs.Id);
    }
     
   }

}

Case class
//Used on the Case object updated 1-31-2020
Public Class VF_CaseServicePartExtController{
private Case css;
   public List<Site_Service_Partner__c> cseList {get;set;}
   
   public VF_CaseServicePartExtController(ApexPages.StandardController sp){
       css= (Case)sp.getRecord();
       cseList = new List<Site_Service_Partner__c>();
       cseList = [SELECT Id,Name,Case__c,Site_Account__c,Primary_Field_Contact__c,Service_Partner__c,
                  Primary_Field_Email__c,Primary_Field_Mobile__c,Service_Partner_Site_Status__c, Contracted_Services__c,
                  Secondary_Field_Contact__c,Secondary_Field_Email__c,Secondary_Field_Mobile__c,Service_Partner_Owner__c,
                  Trade__c,Supported_Trade__c  FROM Site_Service_Partner__c WHERE Case__c =: css.Id AND Trade__c includes('Land','Snow','Land;Snow') AND Service_Partner_Site_Status__c='Active' ];
    
    Set<Id> bidId = new  Set<Id>();  
    for(Site_Service_Partner__c bs:cseList){
       bidId.add(bs.Id);
    }
     
   }
 

}


 
sachinarorasfsachinarorasf
Hi Bob_z,

There is two way :
1. You can create the same method inside any one of the classes.
2. You can call this class with the method inside any one of the classes.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Sachin Arora
www.sachinsf.com