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
Sudhir_MeruSudhir_Meru 

If Condition values or If Condition is failing

Hi, 

 In my below controller something is wrong it is always goind to NULL Pointer Refernce. Please suggest me if there is anything wrong. 

public with sharing class Pagination {

  //URL Passing Parameters.
  String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');    
  String PageAccountId  = ApexPages.currentPage().getParameters().get('AccountId');

/* set controller */
    private ApexPages.StandardSetController setCon;

 
  public Asset   GetAccount{get;set;}
  public Asset   GetContract{get;set;}
 
 
      public pagination ()
    {
      GetAccount = new Asset();    //Get Account Id from Page
      GetContract = new Asset();   //Get Contract Name from Page 
}
 
 
if ( GetAccount.AccountId == NULL & GetContract.Name == NULL )  
         {  
           if ( PageAccountId <> NULL & PageContractId == NULL )
           {
           this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :PageAccountId Order by Service_End_Date_Max__c Desc Limit 1000] );
           }
           else if ( PageAccountId == NULL & PageContractId <> NULL )
           {
           Contract C;
           C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1];
           this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :C.Name Order by Service_End_Date_Max__c Desc  Limit 1000] );
           }
         } 
       else if ( GetAccount.AccountId <> NULL && GetContract.Name == NULL )
        {
         this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId Order by Service_End_Date_Max__c Desc  Limit 1000] );
        } 
       else if ( GetContract.Name <> NULL && GetAccount.AccountId == NULL )
        {
        this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c  = :GetContract.Name Order by Service_End_Date_Max__c Desc  Limit 1000] );
        } 
       else if ( GetAccount.AccountId <> NULL && GetContract.Name <> NULL )
        {
        this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name  Order by Service_End_Date_Max__c Desc  Limit 1000] );
        }           
       else  
      this.setCon = new ApexPages.StandardSetController( [SELECT Id, AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = '0013000000DULXG' Order by Service_End_Date_Max__c Desc Limit 1000] );
  
}

Thanks

Sudhir

Best Answer chosen by Sudhir_Meru
Ramu_SFDCRamu_SFDC
Firstly, change the & to && in all the if and else statements.

All Answers

Ramu_SFDCRamu_SFDC
Firstly, change the & to && in all the if and else statements.
This was selected as the best answer
Sudhir_MeruSudhir_Meru
Thanks Ramu Silly Mistake you saved my time :)