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
haripriya.maturiharipriya.maturi 

Want to display records with EndDate equals to null as well as greater than today in salesforce

The apex controller which iam using is extending DynamicListController. In the constructor i have the code

 

public Level2Controller(){

super('select Id,Name,Approved_By__c,Approval_Date__c,Level2_Active_Status__c,Level2_End_Date__c from Level2__c');

}

 

and in the below method i have the code

 

public override String getWhereClause() {

-

-

-

return 'where Level1__c= \''+useractivelevel[0].Level1__c+'\' and Level2_Active_Status__c=True and (Level2_End_Date__c >='+myDate+' or Level2_End_Date__c=\''+null+'\')';

}

 

but Iam getting following error

 

Attempt to de-reference a null object

 

An unexpected error has occurred. Your development organization has been notified.

 

If at all I query with >=mydate but not with =null , then the query is working fine. Also same conditions working in filter criterias, formula fields and SOQL .

 

Please any body look into this and suggest me.

 

Thanks,

Haripriya

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You don't need to put the null outside the string, as its a literal as far as the query parser is concerned.

 

I think the following should work:

 

return 'where Level1__c= \''+useractivelevel[0].Level1__c+'\' and Level2_Active_Status__c=True and (Level2_End_Date__c >='+myDate+' or Level2_End_Date__c=null)';

 

All Answers

bob_buzzardbob_buzzard

You don't need to put the null outside the string, as its a literal as far as the query parser is concerned.

 

I think the following should work:

 

return 'where Level1__c= \''+useractivelevel[0].Level1__c+'\' and Level2_Active_Status__c=True and (Level2_End_Date__c >='+myDate+' or Level2_End_Date__c=null)';

 

This was selected as the best answer
haripriya.maturiharipriya.maturi
Hi bob,

Thanks for your quick reply

Even I tried with the same query but I got same error as above I said.
haripriya.maturiharipriya.maturi

Hi bob,

 

Its working.  previously I made a typo in the query.

 

Thank you .