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
Melissa Mueller 9Melissa Mueller 9 

Variable is initialized and not out of scope, but I get error saying the variable does not exist

In the following code I get the error: 'Variable does not exist: synchedDates'
From what I am seeing, the list variable synchedDates is initialized and not out of scope. This error occurs in both the Salesforce Developer Console as well as Oracle. 

Even crazier, the first time I refer to that list variable is NOT where the error is being thrown! The error occurs on the first System.debug call on the second IF statement!

It is giving me a headache trying to figure out what could possibly be wrong! PLEASE HELP!!!! 
List<SBQQ__Quote__c> synchedDates =
[Select Id, PSG_Project_Synched__c, StageName__c
From SBQQ__Quote__c
Where QuoteID__c = :psgMasterQuoteToReset[0].PSG_Master_Quote__c 
];
if (synchedDates[0].PSG_Project_Synched__c != null){
System.debug('************The Quote Synch Date Before Assigning Null Was: ' + synchedDates[0].PSG_Project_Synched__c);
synchedDates[0].PSG_Project_Synched__c = null;
System.debug('********Quote Synch Date is now: ' + synchedDates[0].PSG_Project_Synched__c );
}
if (synchedDates[0].StageName__c != 'Bid'){
System.debug('************The Quote Stage Name Before Assigning Bid Was:' + synchedDates[0].PSG_Project_Synched__c);
synchedDates[0].StageName__c = 'Bid';
System.debug('************Quote Stage Name is now: ' + synchedDates[0].StageName__c);
}

 
LBKLBK
Hi Melissa,

Are you sure your SOQL query returns one or more records?

Try this code.
 
List<SBQQ__Quote__c> synchedDates =
[Select Id, PSG_Project_Synched__c, StageName__c
From SBQQ__Quote__c
Where QuoteID__c = :psgMasterQuoteToReset[0].PSG_Master_Quote__c 
];
if(synchedDates != null && synchedDates.size() > 0){
	if (synchedDates[0].PSG_Project_Synched__c != null){
		System.debug('************The Quote Synch Date Before Assigning Null Was: ' + synchedDates[0].PSG_Project_Synched__c);
		synchedDates[0].PSG_Project_Synched__c = null;
		System.debug('********Quote Synch Date is now: ' + synchedDates[0].PSG_Project_Synched__c );
	}
	if (synchedDates[0].StageName__c != 'Bid'){
		System.debug('************The Quote Stage Name Before Assigning Bid Was:' + synchedDates[0].PSG_Project_Synched__c);
		synchedDates[0].StageName__c = 'Bid';
		System.debug('************Quote Stage Name is now: ' + synchedDates[0].StageName__c);
	}
}
Let me know if this helps.
 
Melissa Mueller 9Melissa Mueller 9
I see your point LBK, but I have verified that the query returns data by running it in the query editor with a specific master quote Id that I know is populated and am using to test this. My problem is not that the query does not return data, it is that I cannot run the code because the editor says that my variable does not exist. These two things are far from the same problem.