this code helps me to solve my problem.
I added this on pre-operation on QualifyLead Message
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.MessageName != "QualifyLead")
return;
//Get a reference to the Organization service.
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
//Extract the tracing service for use in debugging sandboxed plug-ins
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
tracingService.Trace("Input parameters before:");
foreach (var item in context.InputParameters)
{
tracingService.Trace("{0}: {1}", item.Key, item.Value);
}
//Modify the below input parameters to suit your requirements.
//In this example, only a Contact record will be created
EntityReference leadid = (EntityReference)context.InputParameters["LeadId"];
var id = leadid.Id.ToString();
RetrieveMultipleRequest rmreq = new RetrieveMultipleRequest();
RetrieveMultipleResponse rmresp = new RetrieveMultipleResponse();
QueryExpression query = new QueryExpression { EntityName = "opportunity", ColumnSet = new ColumnSet("name", "originatingleadid") };
query.Criteria.AddCondition("originatingleadid", ConditionOperator.Equal, id);
query.TopCount = 1;
rmreq.Query = query;
rmresp = (RetrieveMultipleResponse)service.Execute(rmreq);
context.InputParameters["CreateContact"] = false;
context.InputParameters["CreateAccount"] = false;
if(rmresp.EntityCollection.Entities.Count>0)
context.InputParameters["CreateOpportunity"] = false;
else
context.InputParameters["CreateOpportunity"] = true;
tracingService.Trace("Input parameters after:");
foreach (var item in context.InputParameters)
{
tracingService.Trace("{0}: {1}", item.Key, item.Value);
}
}