I need to put an if condition on which if the wire is returning an empty : can anyone help me out for this

wire(tryfh, { chadhad: '$chadhad' }) sdfsdfsdf(result) {

        // Hold on to the wired result value so we can refresh it later
        this.hsdfhsjfhsjf = result;


how to check if result is empty

  • 1
    Hi, and welcome to SFSE! Can you please be a bit more specific? What do you mean by "empty"? An empty list? A null value? A map with no fields?
    – sfdcfox
    May 15, 2020 at 14:13
  • If(result.data.length){ } May 15, 2020 at 14:30

1 Answer 1


I had this issue today, the way to check this is with a getter method on the component

get hasDuplicates(){
    if(this.dupLeads && this.dupLeads.length){
        return true;
    return false;

Make sure to check for BOTH the variable and then the variable length (as I'm doing in my if statement). This is because the getter is apparently called multiple times while the page is being loaded, and the first few times, the wired variable will be undefined, which will cause an error if you try to access the .length property.

So first you check if it's defined, and if so, check if it has a length property. If it has then it means that the wire service returned some data (as opposed to an empty "data" object).

  • 1
    We now have the null-safe operator, so you can simply write get hasDuplicates() { return this.dupLeads?.length > 0; }
    – sfdcfox
    Nov 3, 2021 at 16:13

You must log in to answer this question.

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