I try to add objects from 'accbetween' to 'idlist' (see the code below):
public class SearchTestApex {
public list <Fund__c> idlist {get;set;}
public list <Fund__c> accbetween = new list<Fund__c>();
public String idsaved {get;set;}
public String searchKey {get;set;}
public SearchTestApex( ) {
}
public void search(){
String searchquerybetween='SELECT Id, Product__r.Id, Product__r.Name, Date__c FROM Fund__c WHERE Code__c LIKE \'%'+searchKey+'%\' ORDER BY Product__r.Id, Date__c DESC';
accbetween= Database.query(searchquerybetween);
//Then, I simply try to add the first value of accbetween to idlist:
idlist.add(accbetween[0]);
}
}
There is a VisualForce code which is supposed to display 'idlist' but it returns the error as follow:
Attempt to de-reference a null object
I assume I might have to initialize 'idlist' or there could be an incompatibility between these types of list. Why do I get this error? How can I fix it?