public void MoveToStateAndExecuteActions(Item item, ID workflowStateId)
{
Sitecore.Workflows.IWorkflowProvider workflowProvider = Item.Database.WorkflowProvider;
Sitecore.Workflows.IWorkflow workflow = workflowProvider.GetWorkflow(item);
// if item is in any workflow
if (workflow != null)
{
using (new Sitecore.Data.Items.EditContext(item))
{
// update item's state to the new one
item[Sitecore.FieldIDs.WorkflowState] = workflowStateId.ToString();
}
Item stateItem = ItemManager.GetItem(workflowStateId,
Language.Current, Sitecore.Data.Version.Latest, item.Database, SecurityCheck.Disable);
// if there are any actions for the new state
if (!stateItem.HasChildren)
return;
WorkflowPipelineArgs workflowPipelineArgs = new WorkflowPipelineArgs(item, null, null);
// start executing the actions
Pipeline pipeline = Pipeline.Start(stateItem, workflowPipelineArgs);
if (pipeline == null)
return;
WorkflowCounters.ActionsExecuted.IncrementBy(pipeline.Processors.Count);
}
}
Thanks to this thread