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
jucuzoglujucuzoglu 

Why is this List Null?

For some reason this list in my constructor is showing up as null.

 

Here is a partial code snippit with some info modified to focus on the problem.

 

public class PlacementPreferenceFormController {

	public LIST<Partner_Research__c> temp_prl;
	public LIST<Partner_Research__c> prl {get; set;}
	
	public PlacementPreferenceFormController(){
		
		// Display list of potential placements
		temp_prl = [select id,State__c,City__c,Organization_Type__c,Organization_Name__r.Name 
		from Partner_Research__c
		Where Organization_Name__c IN 
			(Select AccountId From Opportunity 
			Where TBR_Partner_Year__c = 'TBR Partner 2011' AND StageName = 'Position Ready for Matching')
			Order by Organization_Type__c];

		// Remove Duplicates
		
		string allIds = '';
		string stringCompare = '';
		for (Partner_Research__c s : temp_prl) {
			stringCompare = s.Id;			
		  	if (!allIds.contains(stringCompare)){
		    	system.debug('******************************');
		    	system.debug(!allIds.contains(stringCompare));
		    	system.debug('******************************');
		    	system.debug(s);
		    	system.debug(prl);		    	
		    	prl.add(s);
		    	allIds = allIds + ',' + s.Id;
		  	}
		}		

	}

 I get an error in the line prl.add(s); When I debut the prl object I get null back instead of an empty (or populated) list.

 

Any idea why the prl object is null and how I can correct this. Perhaps its a problem of scope?

Best Answer chosen by Admin (Salesforce Developers) 
Dirk GronertDirk Gronert

Because you never instantiated the prl variable!!!

 

public class PlacementPreferenceFormController {

	public LIST<Partner_Research__c> temp_prl;
	public LIST<Partner_Research__c> prl {get; set;}
	
	public PlacementPreferenceFormController(){
		prl = new List<Partner_Research__c>();  // here you go!!!!!!!!!!!
		// Display list of potential placements
		temp_prl = [select id,State__c,City__c,Organization_Type__c,Organization_Name__r.Name 
		from Partner_Research__c
		Where Organization_Name__c IN 
			(Select AccountId From Opportunity 
			Where TBR_Partner_Year__c = 'TBR Partner 2011' AND StageName = 'Position Ready for Matching')
			Order by Organization_Type__c];

		// Remove Duplicates
		
		string allIds = '';
		string stringCompare = '';
		for (Partner_Research__c s : temp_prl) {
			stringCompare = s.Id;			
		  	if (!allIds.contains(stringCompare)){
		    	system.debug('******************************');
		    	system.debug(!allIds.contains(stringCompare));
		    	system.debug('******************************');
		    	system.debug(s);
		    	system.debug(prl);		    	
		    	prl.add(s);
		    	allIds = allIds + ',' + s.Id;
		  	}
		}		

	}