Activity Forums Salesforce® Discussions How to check if a string is empty in Apex in Salesforce?

  • How to check if a string is empty in Apex in Salesforce?

    Posted by Anjali on August 28, 2020 at 12:16 PM

    How to check if a string is empty in Apex in Salesforce?

    Anuj replied 6 years ago 3 Members · 2 Replies
  • 2 Replies
  • Kirandeep

    Member
    August 28, 2020 at 2:31 PM

    Hi,
    You can use isEmpty() method of String Class which returns true if the specified String is Empty OtherWise returns false

    • This reply was modified 6 years ago by  Kirandeep.
    • This reply was modified 6 years ago by  Kirandeep.
  • [adinserter block='9']
  • Anuj

    Member
    August 28, 2020 at 3:07 PM

    public String CheckIt {get;set;}

    //Check IsNotEmpty
    public Boolean CheckisNotEmpty()
    {
    if(String.isNotEmpty(CheckIt))
    {
    //String is not empty ('') and not null
    return true;
    }
    else
    {
    //String is empty ('') or blank or null
    return false;
    }
    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos