+ Start a Discussion
d3developerd3developer 

System.StringException when comparing blank String against Id

Somewhat surprised that this doesn't work:

 

 

				if(g.showRule.Form_Field__c == null || g.showRule.Form_Field__c == '')
g.showRule.Form_Field__c = ffid;

 

Not a big deal since I can remove the test.

 

Full error:

 

 

 System.StringException: Invalid id:

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
d3developerd3developer

Nope. But you could do this if you really care:

 

 

				if ((g.showRule.Form_Field__c == null ) || (((String) g.showRule.Form_Field__c) == ''))
					g.showRule.Form_Field__c = ffid;				

 

 

All Answers

Jeremy.NottinghJeremy.Nottingh

Try it with parentheses around each Boolean expression, and another set around the full expression:

if ((g.showRule.Form_Field__c == null ) || (g.showRule.Form_Field__c == ''))
g.showRule.Form_Field__c = ffid;
Jeremy
d3developerd3developer

Nope. But you could do this if you really care:

 

 

				if ((g.showRule.Form_Field__c == null ) || (((String) g.showRule.Form_Field__c) == ''))
					g.showRule.Form_Field__c = ffid;				

 

 

This was selected as the best answer