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
Peter Martensen 8Peter Martensen 8 

Can someone help me break this IF statement into a nested IF statement so I can add system.debug between the conditions?

if( ('Closed Won' == o.StageName) && ('Closed Won' != opportunityOldMap.get(o.Id).StageName) && (!o.Line_of_Service__c.contains('Agawam')))
Can someone help me break this IF statement into a nested IF statement so I can add system.debug between the conditions?  Thanks
 
Best Answer chosen by Peter Martensen 8
Colton WehkingColton Wehking
Here you go
 
System.debug('Condition 0');
if('Closed Won' == o.StageName){
	System.debug('Condition 1');
	
	if('Closed Won' != opportunityOldMap.get(o.Id).StageName) {
		System.debug('Condition 2');
		
		if(!o.Line_of_Service__c.contains('Agawam')) {
			System.debug('Condition 3');
		}
	}
}

 

All Answers

Colton WehkingColton Wehking
Here you go
 
System.debug('Condition 0');
if('Closed Won' == o.StageName){
	System.debug('Condition 1');
	
	if('Closed Won' != opportunityOldMap.get(o.Id).StageName) {
		System.debug('Condition 2');
		
		if(!o.Line_of_Service__c.contains('Agawam')) {
			System.debug('Condition 3');
		}
	}
}

 
This was selected as the best answer
Peter Martensen 8Peter Martensen 8
Thanks!
Peter Martensen 8Peter Martensen 8
Colton,
I added your code, then ran the test class.  The first line of code "if('Closed Won' == o.StageName){" is blue for code coverage, but the System.debug('Condition 1') statement isn't showing up in the log.  Do you know why it isn't?  The next two Conditions are red for code coverage and those Conditions aren't showing up in the logs either.  Condition 0 is showing up in the log.
Colton WehkingColton Wehking
An If statement will appear blue if it's evaluated, even if the expression inside it is false. This probably means that o.StageName is not equal to 'Closed Won'.

I'd recommend adding another System.debug above it, where Condition 0 is, to check what StageName is. It's possible something else in the code is causing an issue
System.debug('Condition 0');
System.debug(o.StageName);
if('Closed Won' == o.StageName){

 
Peter Martensen 8Peter Martensen 8
OK.  Thanks.  I didn't realize the code turned blue even if the expression is false.