Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

i'm getting an error as below, when i try to retrieve account lookup id in opportunity entity through plugin

Posted on by 10

The error

ystem.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Opportunity1.subgrid.Execute(IServiceProvider serviceProvider)

The Code

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


EntityReference ownerLookup = (EntityReference)entity.Attributes["parentaccountid"];
Guid accountid = ownerLookup.Id;

 

can any one help me here?

  • Suggested answer
    cmrtest1 Profile Picture
    cmrtest1 10 on at
    RE: i'm getting an error as below, when i try to retrieve account lookup id in opportunity entity through plugin

    thanks,that works good

  • Verified answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: i'm getting an error as below, when i try to retrieve account lookup id in opportunity entity through plugin

    Hi,

    I guess your plugin is executed when the opportunity is updated. If this is true, and you don't change the field "parentaccountid", your target will not contain this field. You will need to perform a retrieve: 

    opportunity = service.retrieve(entity.id, entity.id, new ColumnSet("parentaccountid"))

    Guid accounId = opportunity.GetAttributeValue<EntityReference>("parentaccountid").Id;

  • cmrtest1 Profile Picture
    cmrtest1 10 on at
    RE: i'm getting an error as below, when i try to retrieve account lookup id in opportunity entity through plugin

    Target = opportunity

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans