Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
vfpage controller

global class Search_Account_Controller {

   public Set<string> accountSet{get;set;}

   public string accName{get;set;}

   public Account accObj{get;set;}

   public List<Opportunity> oppList{get;set;}

   public boolean recTypeCheck{get;set;}

   public List<Service__c> serviceList{get;set;} 

   

    public Search_Account_Controller() {

         recTypeCheck=true;

        accountSet = new Set<String>();

        List<Account> accList = [Select id, Name, Account_Type__c from Account LIMIT 30000];

        if(accList!=null && accList.size()>0){

            for(Account acc :accList){

                accountSet.add(acc.Name);

            }

        }

    }

    

     public void getAccountDetails(){

        oppList = new List<Opportunity>();

        serviceList= new List<Service__c>();

         List<Account> accList= [Select Name, Id, Account_Type__c from Account where Name=:accName LIMIT 1];

         

         if(accList!=null && accList.size()>0)

         accObj=accList[0];

         

        if(accObj.Account_Type__c!='Client')  {

             recTypeCheck=false;

         }

         else{

            oppList=[Select Id, OppNumber__c, FC_Opportunity_Status__c, Name, StageName, CloseDate, CreationDateTime__c from Opportunity where AccountId=:accObj.Id];    

         }

     }

     

     public void getLineItemDetails()  {

         String oppIdval = apexpages.currentpage().getparameters().get('OppId');

         serviceList=[Select Id, Product__c, Produkt_ID__c , Product__r.Name, Name from Service__c where Opportunity__c=:oppIdval];    

         

     }

}
3 answers
  1. Jul 8, 2019, 4:32 PM
    Hi Nishant,

    'accName' variable is not initialized so in method 'getAccountDetails()' there will be no result for 'accList' i.e. accList will be null. Due to this 'accObj' will also be null and it will throw exception where you are checking 'accObj.Account_Type__c!='Client''.

    So in Search_Account_Controller constructor initialize 'accName' & 'accObj' :

    public Search_Account_Controller() {

    recTypeCheck=true;

    accountSet = new Set<String>();

    accName = '';

    accObj = new Account();

    List<Account> accList = [Select id, Name, Account_Type__c from Account LIMIT

    30000];

    if(accList!=null && accList.size()>0){

    for(Account acc :accList){

    accountSet.add(acc.Name);

    }

    }

    }

    Also update 'getAccountDetails()' method :

    public void getAccountDetails(){

    oppList = new List<Opportunity>();

    serviceList= new List<Service__c>();

    List<Account> accList= [Select Name, Id, Account_Type__c from Account where

    Name=:accName LIMIT 1];

    if(accList!=null && accList.size()>0){

    accObj=accList[0];

    if(accObj.Account_Type__c!='Client') {

    recTypeCheck=false;

    }

    else{

    oppList=[Select Id, OppNumber__c, FC_Opportunity_Status__c, Name,

    StageName, CloseDate, CreationDateTime__c from Opportunity where

    AccountId=:accObj.Id];

    }

    }

    }

     
Loading
0/9000