Here is code which changes workflow state and executes actions:
public static WorkflowResult ChangeStateAndExecuteActions(Item item, ID workflowStateId)
{
using (new EditContext(item))
{
item[FieldIDs.WorkflowState] = workflowStateId.ToString();
}
Item stateItem = item.Database.GetItem(workflowStateId);
if (stateItem.HasChildren)
{
WorkflowPipelineArgs workflowPipelineArgs = new WorkflowPipelineArgs(item, null, null);
Pipeline pipeline = Pipeline.Start(stateItem, workflowPipelineArgs);
if (pipeline != null)
{
WorkflowCounters.ActionsExecuted.IncrementBy(pipeline.Processors.Count);
}
}
return new WorkflowResult(true, "OK", workflowStateId);
}
I wrote it 4 years ago but it should still work.
You can read more in my blog post here:
https://www.cognifide.com/our-blogs/sitecore/changing-workflow-state-of-sitecore-items-programmatically/