-1

Could you please help me make a !=null check here?

public static Integer getUserOpenCasesBasedOnTerritory(String userId) 
{
  return getUserOpenCasesListBasedOnTerritory(userId).size();
 }

4 Answers 4

0

You can get the results into a list which is being returned by getUserOpenCasesListBasedOnTerritory and then have a null check.

Assuming that it is returning List<Case> your code should be something like this

public static Integer getUserOpenCasesBasedOnTerritory(String userId) 
{
    List<Case> cases = getUserOpenCasesListBasedOnTerritory(userId);
    return cases !=null ? cases.size() : 0; 
}

You can replace Case with the return type that is being returned from your method.

2
  • Yes Thanks a lot!)
    – Artem
    Commented Jul 16, 2020 at 7:57
  • Pleased to help ! Commented Jul 16, 2020 at 8:25
0
public static Integer getUserOpenCasesBasedOnTerritory(String userId) {

//Return a value when getUserOpenCasesListBasedOnTerritory(userId) is null, say, -1, for example
Integer re_Value = -1; 

if(getUserOpenCasesListBasedOnTerritory(userId)!=null && !isEmpty(getUserOpenCasesListBasedOnTerritory(userId)){
   re_Value = getUserOpenCasesListBasedOnTerritory(userId).size();
}

return re_Value;

}
4
  • ERROR - "No apex action available for ABI_CXC_Account360_Helper.getUserOpenCasesBasedOnTerritory"
    – Artem
    Commented Jul 16, 2020 at 7:28
  • What is the content of "getUserOpenCasesListBasedOnTerritory"? Commented Jul 16, 2020 at 7:36
  • There are List of Cases
    – Artem
    Commented Jul 16, 2020 at 7:39
  • You can try "List<Case> lstCases = getUserOpenCasesListBasedOnTerritory(userId)". Then check if lstCases.size() == 0 Commented Jul 16, 2020 at 7:45
0

You can leverage String class method to check if the specified String has white space, empty (''), or null. You can have this if condition and return the results accordingly.

String.isNotBlank(inputString) - Returns true if the specified String is not whitespace, not empty (''), and not null; otherwise, returns false.

String.isBlank(inputString)- Returns true if the specified String is white space, empty (''), or null; otherwise, returns false.

0

You can store the response of getUserOpenCasesListBasedOnTerritory(userId) method in a list variable and have not null on the variable.

Something like -

    Integer iCount=0;
    List<Case> lstCases = getUserOpenCasesListBasedOnTerritory(userId);
    if(lstCases!= null){
    iCount = lstCases.size();
    }
    return iCount;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .