zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    uva 1510
    ADN中国团队參加微软的Kinect全国大赛获得三等奖
    在 window7 window8下公布webService注意问题
    html5调用手机摄像头,实现拍照上传功能
    4、深入理解Bean
    恶补jquery(四)jquery中事件--冒泡
    html5css3杂记
    Core Data 和 sqlite3的性能对比【图】3gs,iPhone4,4s,5的性能测试。
    boost 的函数式编程库 Phoenix入门学习
    information_schema模式表介绍 processlist
  • 原文地址:https://www.cnblogs.com/janmson/p/2880032.html
Copyright © 2011-2022 走看看