• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MSCRM janmson
MS CRM顾问及二次开发
博客园    首页    新随笔    联系   管理    订阅  订阅

QualifyLead PlugIn(转)

QualifyLead PlugIn

Supposing you needed some custom logic to happen immediately after a lead was qualified. You can achieve this by registering a Plug-in on the QualifyLead Post Operation stage. From within this Plug-in you can easily get a reference to the newly created Account, Contact and Opportunity and make any changes you need.

Inside the PlugIn you need the following code:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
IOrganizationService service = localContext.OrganizationService;
// Get the qualified lead
EntityReference leadid = (EntityReference) localContext.PluginExecutionContext.InputParameters["LeadId"];
Lead lead = (Lead)service.Retrieve(leadid.LogicalName, leadid.Id,new ColumnSet(LeadAttributes.crm_AccountType));
 
// Get the newly created account, contact, opportunity
Contact contact = null;
Opportunity opportunity = null;
Account account = null;
foreach (EntityReference created in (IEnumerable<object>) localContext.PluginExecutionContext.OutputParameters["CreatedEntities"])
{
    switch (created.LogicalName)
    {
        case Contact.EntityLogicalName:
            contact = (Contact)service.Retrieve(Contact.EntityLogicalName, created.Id, new ColumnSet(true));
            break;
        case Account.EntityLogicalName:
            account = (Account)service.Retrieve(Account.EntityLogicalName, created.Id, new ColumnSet(true));
            break;
        case Opportunity.EntityLogicalName:
            opportunity = (Opportunity)service.Retrieve(Opportunity.EntityLogicalName, created.Id, new ColumnSet(true));
            break;
 
    }
}

If you need to make any changes to the created records, you can simply use:

?
1
2
contact.LastName = "some change";
service.Update(contact);

Hope this helps.

posted @ 2013-01-28 15:38  韩建兴  阅读(243)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3