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
SimrinSimrin 

If condition check for blank space

public with sharing class Controller1{

    public String temp1 {get;set;}
    public String temp2 {get;set;}

    public void test() {
        //temp1 ='someValue' and temp2='SomeValu1'
	if(temp1 != '' && temp1 != null && temp2 != '' && temp2 != null){

		//Manipulation
	}
    }

}
I had above piece of code, which checked if condition properly, but when i moved code to Sandbox, the if condition always fails.

Any suggestions and reason for cause, if known ?
Best Answer chosen by Simrin
kevin lamkevin lam
I'm not sure why it fails in your sandbox but I always use the isBlank or isEmpty methods:
  • String.isBlank(temp1) - returns true if the string is not whitespace, not empty (''), and not null.
  • String.isEmpty(temp1) - returns true if the string is empty ('') or null.