web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How To Check in Plugin If a Lead Record Is Created by Email?

(0) ShareShare
ReportReport
Posted on by 535

Hi,

I am trying to do some custom things when a Lead is being created by Email activity. I am using as is Convert To button, i registered a plugin in Lead Create Message, when i check the attributes of the Target i can't see any attribute about this record is being created by E-mail Convert to. Which attribute should i check? My plugin is in PreOutsideTransaction

Thanks

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    The only idea that I have in mind is to check "ParentContext" for some additional information. If it doesn't contain it - I'm afraid it will be really hard to define the origin of the lead creation.

  • Verified answer
    Modesto Iacopino Profile Picture
    on at

    Hello Furkan,

    you can check the parent context like the following:

    public void Execute(IServiceProvider serviceProvider)

           {

               // Obtain the execution context from the service provider.  

               IPluginExecutionContext context = (IPluginExecutionContext)

                   serviceProvider.GetService(typeof(IPluginExecutionContext));

               ITracingService tracingService =

                   (ITracingService)serviceProvider.GetService(typeof(ITracingService));

               // Obtain the organization service reference.

               IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

               IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

               if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)

               {

                   Entity entity = (Entity)context.InputParameters["Target"];

                   if (entity.LogicalName == "lead")

                   {

                       Entity lead = entity;

                       if (context.ParentContext.ParentContext != null && context.ParentContext.ParentContext.PrimaryEntityName == "activitypointer")

                       {

                           tracingService.Trace("The lead was created by " + context.ParentContext.ParentContext.InputParameters["ActivityEntityName"].ToString());

                       }

                   }

               }

           }

    Enabling the plugin trace in your org you can see that if you use Convert To inside Email, you will have something like:

    pastedimage1593180532595v1.png

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    When Lead gets created from Email, Email regarding field will be set to newly created lead. So you can check if newly created lead has any existing Email associated based on regarding. This way you will come to know that lead has created from Email using convert to ribbon button.

    If found helpful, Please mark my answer verified.

  • furkank Profile Picture
    535 on at

    I found that ParentContext.MessageName is Convert Activity. So this resolves my problem. Thanks

  • furkank Profile Picture
    535 on at

    This is works too thanks

  • furkank Profile Picture
    535 on at

    Unfortunately, in the Unified Interface this convert to lead works different and it is giving parent context null. It is fine when not using unified interface. Aynone got idea why same process giving parent context null in Unified Interface...

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I played a bit and unfortunately I see the same result also I have no other ideas unfortunately.

  • furkank Profile Picture
    535 on at

    @Bipin Kumar

    Hello, i tried your suggestion but unfortunately when this process is happening on Unified Interface, the regarding field does not set. It stays empty. Again working different from usual. Do you know if i can plug in this process and do this step manually?

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 96 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans