3

I have array with list of class.

public class filterField {
    public String label {get;set;}
    public String searchFieldName {get;set;}
    public String searchValue {get;set;}

    public filterField(String a,String b,String  c) {
        this.label=a;
        this.searchFieldName =b;
        this.searchValue  =c;
    }

}  

public filterField [] filterArray {get;set;}
filterArray = new filterField[]{};

FilterArray is list of class. I try to get the value of class string values. I tried below.

apex:

for(integer i=0;i<filterArray.size();i++) {
    system.debug('value insude for:::::'+filterArray.get(i).searchValue);

    string s=filterArray.get(i).searchValue;

    if(filterArray.get(i).searchValue!=null || filterArray.get(i).searchValue!='') {

        system.debug('value ins:::::'+filterArray.get(i).searchValue);
        String strField=filterArray.get(i).searchFieldName +':'+'"'+filterArray.get(i).searchValue+'"';
        strFilterField+=strField;
    }
}

My array values are :

filterField:[label=AccountName, searchFieldName=FULL_NAME, searchValue=], 
filterField:[label=City, searchFieldName=PRIM_CITY, searchValue=test], 
filterField:[label=Country, searchFieldName=PRIM_COUNTRY_NM, searchValue=], 
filterField:[label=Street Address, searchFieldName=PRIM_ADDR_LN_1, searchValue=], 
filterField:[label=State/Province, searchFieldName=PRIM_STATE, searchValue=test], 
filterField:[label=Zip/PostalCode, searchFieldName=PRIM_POSTAL_CD, searchValue=]
1
  • 2
    String.isBlank(someString);
    – d_k
    Apr 26, 2017 at 8:33

2 Answers 2

14

Use String.isBlank(yourString) to check if it's null or '' or ' '. This method detects whether string has null or blank space or just quotes.

Example:

String str = 'searchValue';
System.assertEquals(false,String.isBlank(str));   // returns false since string is not blank
0

String.isEmpty(yourString); isEmpty method will also help in checking.

2
  • 4
    Important to not the different is that this method does NOT detect a sting containing only whitespace when compared to isBlank
    – Eric
    Apr 26, 2017 at 14:20
  • Agreed with eric Apr 26, 2017 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.