0

I am needing to run an advanced query in a Record Triggered Lightning Flow that references parent objects. The query runs, but I cannot figure out how to get it to run in an invokable method. I am passing the asset Id to the Apex and then wanting to return the list that my query returns.

I am trying to run the query from an invokable method inside a lightning flow. I am passing the record to the flow. In the debug logs it shows the query and then immediately after it shows the error below.

I receive the following error:

Error Occurred: An Apex error occurred: System.UnexpectedException: Bad rightOperand type: got SObjectScriptRow: operator e dataType 1

public with sharing class queryAssets{
@InvocableMethod(label='Get assets' description='Runs a complex query and returns a list of assets.')
    public static List<Asset> GetAssets (List<Asset> curAssets) {
       for(Asset assetObj :  List<Asset> assetsList = [Select Id, Name, AccountId, 
                              FROM Asset
                              Where Id IN: curAssets
                              AccountId != NULL 
                              AND (Product2.Cost__c != null OR Product2.Dealer_Cost__c!= null 
                              OR Product2.Dealer_Labor_Charge__c != null)
                                                       AND Quantity != null]) {
                                                           
            return assetsList;                                                   
                          }
    }
}
5
  • Where are you stuck, exactly?
    – Adrian Larson
    Feb 9, 2021 at 15:43
  • I get the following error: Error Occurred: An Apex error occurred: System.UnexpectedException: Bad rightOperand type: got SObjectScriptRow: operator e dataType 1 Feb 9, 2021 at 15:52
  • Please edit your post with any clarifications. You should always include any error messages verbatim. We are not mind readers.
    – Adrian Larson
    Feb 9, 2021 at 15:57
  • Also showing us how you are trying to call this code would likely help. The more we have to fill in the gaps, the less likely you will receive a timely and useful answer to your question.
    – Adrian Larson
    Feb 9, 2021 at 16:00
  • It looks like you might have an issue with the data your SOQL bind variable is trying to access. Can you try Mapping your List<Asset> curAssets to new Map<Id, Asset>(curAssets).keySet() and then access the Map keySet in your bind variable?
    – TSmith
    Feb 9, 2021 at 16:33

1 Answer 1

0

I'm not certain I understand exactly what the error message means, but I suspect it is referring to the 'rightOperand' in your for loop, where you are declaring a List variable. See For Loops in the Apex Dev Guide for the correct syntax. Additionally, your query is not valid (extra comma, missing AND), and you are trying to return inside the loop. Assuming your input and output types are correct, I think you want this:

public with sharing class queryAssets{
    @InvocableMethod(label='Get assets' description='Runs a complex query and returns a list of assets.')
    public static List<Asset> GetAssets(List<Asset> curAssets) {
        // retrieve results
        List<Asset> assetsList = [
            SELECT Id, Name, AccountId 
              FROM Asset
             WHERE Id IN :curAssets
               AND AccountId != NULL 
               AND (Product2.Cost__c != null 
                    OR Product2.Dealer_Cost__c!= null 
                    OR Product2.Dealer_Labor_Charge__c != null)
               AND Quantity != null
        ];  
        // if you need to further modify/filter results, you could do so here.

        // return results
        return assetsList;                                                   
    }
}

You must log in to answer this question.

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