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
GeneRegistryGeneRegistry 

Implement a Flow from Apex Code

I am trying to call a Flow (not workflow but flow) from inside a trigger:

trigger OpportunityTriggerAfter on Opportunity (after insert,after update) {
public Flow.Interview.Update_Opportunity_w_Favorite_Venue_Info fl;
for(Opportunity o:Trigger.New){

if(Trigger.isInsert){
   		                     
fl.vaOpportunityID = o.Id;

}
}

 although I'm not certain if you can do this or if this is even the correct syntax. I'm also getting a CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY error even though the flow I am calling doesn't perform an update on the Opportunity but instead only takes the opportunity ID as a starting parameter. If I try fl = new Flow.Interview.Update_Opportunity_w_Favorite_Venue_Info(o.Id); I get a constructor not defined error even though this can be done in the following doc: http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_flows_advanced.htm

My questions are:

1.) Is this even possible? If so what is the syntax (do I have the correct syntax)?
2.) Why am I getting the CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY error?

suresh.csksuresh.csk

Hi

 

I think you your scenario is like this

1.After insert your trigger is fired.

2.trigger calls a work flow

so in this the workflow again update the field which again calls the  trigger (after update),

so it looks like a recurisve action.

So you should not fire the trigger(after update )when work flow updates the field.

Use a static variable like updateTrigger (ON/OFF) to control the excution of trigger.

 

I think my reply makes sense and matched your question

 

Vinita_SFDCVinita_SFDC

Hello,

 

Please refer : http://boards.developerforce.com/t5/Visual-Workflow/Dynamic-redirect-from-a-VF-page-with-an-embedded-Flow/td-p/359813 which explains how we can make use of apex and Visual force for enhancing our flows.

Regarding your second question: there could be many reasons for thsi error "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY " please refer following link which cover few reasons for this error:

http://boards.developerforce.com/t5/Apex-Code-Development/CANNOT-INSERT-UPDATE-ACTIVATE-ENTITY-on-opportunityContactRole/td-p/65352

Hope this helps!

GeneRegistryGeneRegistry



Well this doesn't call a workflow. It calls a (visual) flow. They are different and flows are not listed under the order of execution. Also the flow does not call the trigger again since the trigger is an after insert after update trigger on the opportunity and the flow does no work on the opportunity.

GeneRegistryGeneRegistry



I was really hoping to do this without a VF page. It seems we should have the ability to trigger flows directly from apex code without a VF page. A VF page seems like a rather roundabaout approach, but if it is the only way then I guess I have no choice in the matter.

As for your second link, it doesn't apply to me. Seems that person had a similar error message but for a different reason.