function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TN AdminTN Admin 

Passing collection variable and opportyid from apex trigger to flow


I want to pass collection variable (Contains list of Oppty lineitems) and opportunityId to flow. Please let me know if am doing wrong.
 
trigger OpptyLineItem on OpportunityLineItem(before delete) {
 if(trigger.IsBefore){ 
   if(trigger.IsDelete){

        List<OpportunityLineItem> opptyLineItemList= [select Id,Name__c,OpportunityId,PricebookEntry.Product2.Name FROM OpportunityLineItem Where OpportunityId =: trigger.old[0].OpportunityId];

            Map<String,Object> productAlignmentTOoppty = new Map<String, Object>();          
            system.debug('productAlignmentTOoppty '+ productAlignmentTOoppty); 

             for(OpportunityLineItem Oli: opptyLineItemList){
               if(Oli.Id != trigger.old[0].Id){
               system.debug('test');
                   // productAlignmentTOoppty.put('varOpptyDel',Oli);
                    productAlignmentTOoppty.put('varOpportunityId',Oli.OpportunityId);
               }
             }

            Flow.Interview.MyFlow refToFlow = new Flow.Interview.MyFlow(productAlignmentTOoppty);
            refToFlow.start();


    }
 }

 
NagendraNagendra (Salesforce Developers) 
Hi,

First - this trigger will only handle deletion on on opportunity at a time, which is not good practice.

Second - you list of line items specifies Where OpportunityId =: trigger.old[0].OpportunityId]; in the query. Within the loop, you check for if(Oli.Id != trigger.old[0].Id){... seems like you want == instead, and you don't really even need that because of the query.

Regards,
Nagendra.P