• Charni Wiggins 13
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Record triggered flow, working absolutely fine for one record but receiving the following error when we create multiple records..

The number of results does not match the number of interviews that were executed in a single bulk execution request.
 
public with sharing class FlowInvokableOpportunityLineItemHandler {


    @InvocableMethod(
        label = 'Opportunity Product from Opportunity Accounts'
        description = 'Given list of Accounts return list of OLIs from that account and parent account'
    )

    public static List<List<OpportunityLineItem>> runOppLineItems( List<ID> accIds ) {
        List<OpportunityLineItem> oLIs = new List<OpportunityLineItem>();
        List<Id> accountsIds = new List<Id>();
        List<Account> accIncParents = [SELECT Id, ParentId FROM Account WHERE Id IN: accIds];

        for (Account acc : accIncParents){
            if(acc.ParentId == NULL){
                accountsIds.add(acc.Id);
            }
            else{
                accountsIds.add(acc.Id);
                accountsIds.add(acc.ParentId);
            }
        }
        system.debug('accountsIds >>>>' + accountsIds);

        List<Opportunity> opps = [SELECT Id FROM Opportunity WHERE AccountId IN : accountsIds AND Opportunity.StageName != 'Closed Lost'];
        List<OpportunityLineItem> oLI = [SELECT Id, Product_Family__c, Product2.Name FROM OpportunityLineItem WHERE OpportunityId in :opps];
        
        system.debug('OLI >>>>' + oLI);
        List<List<OpportunityLineItem>> itemListList = new List<List<OpportunityLineItem>>();
        //add the list opps to the list of lists
        itemListList.add(oLI);
        system.debug('itemListList >>>>' + itemListList);

        // send list of lists to the Flow	
        return itemListList;        

    }
}

 
Record triggered flow, working absolutely fine for one record but receiving the following error when we create multiple records..

The number of results does not match the number of interviews that were executed in a single bulk execution request.
 
public with sharing class FlowInvokableOpportunityLineItemHandler {


    @InvocableMethod(
        label = 'Opportunity Product from Opportunity Accounts'
        description = 'Given list of Accounts return list of OLIs from that account and parent account'
    )

    public static List<List<OpportunityLineItem>> runOppLineItems( List<ID> accIds ) {
        List<OpportunityLineItem> oLIs = new List<OpportunityLineItem>();
        List<Id> accountsIds = new List<Id>();
        List<Account> accIncParents = [SELECT Id, ParentId FROM Account WHERE Id IN: accIds];

        for (Account acc : accIncParents){
            if(acc.ParentId == NULL){
                accountsIds.add(acc.Id);
            }
            else{
                accountsIds.add(acc.Id);
                accountsIds.add(acc.ParentId);
            }
        }
        system.debug('accountsIds >>>>' + accountsIds);

        List<Opportunity> opps = [SELECT Id FROM Opportunity WHERE AccountId IN : accountsIds AND Opportunity.StageName != 'Closed Lost'];
        List<OpportunityLineItem> oLI = [SELECT Id, Product_Family__c, Product2.Name FROM OpportunityLineItem WHERE OpportunityId in :opps];
        
        system.debug('OLI >>>>' + oLI);
        List<List<OpportunityLineItem>> itemListList = new List<List<OpportunityLineItem>>();
        //add the list opps to the list of lists
        itemListList.add(oLI);
        system.debug('itemListList >>>>' + itemListList);

        // send list of lists to the Flow	
        return itemListList;        

    }
}