Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Get all contacts related to a marketing list.

Posted on by 795

Hi,

I have created a dynamic list type  and added members based on a dynamic query using Advanced find. I just want to access all the contacts (5000+) using my MVC application . But, due to large number of records, exception is thrown. Can you please help me out how can i resolve this issue by using pagination in this?

Thank you

*This post is locked for comments

  • Emre GULCAN Profile Picture
    Emre GULCAN 2,379 on at
    RE: Get all contacts related to a marketing list.

    Hi,

    LinkEntity is not related max record count that you get, it's like SQL JOIN that helps you get data from different - related entities.

  • Verified answer
    CRM Beginner  Profile Picture
    CRM Beginner 795 on at
    RE: Get all contacts related to a marketing list.

    Thanks all.. I resolved it using the concept of Link Entity in CRM

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Get all contacts related to a marketing list.

    With the fetchexpression, it could be a combination of this:

    lazarus987.wordpress.com/.../how-to-retrieve-contacts-from-marketing-list-using-crm-2011-sdk-3

    and this:

    msdn.microsoft.com/.../gg328046.aspx

  • Suggested answer
    Emre GULCAN Profile Picture
    Emre GULCAN 2,379 on at
    RE: Get all contacts related to a marketing list.

    Hi,

    XrmLibrary 's "GetMemberList" method using loop to get all records (100 or 10000 doesn't matter) and default item limit is 5000 and you can set it when you call method. This limit (5000) is ideal for performance (as Microsoft recommended) and if you set lower value this increase OrganizationService call number.

    For example you have 25000 members in your marketing list and you set 1000 this limit, XrmLibrary's GetMemberList method running 25 times to fetch all data, if you set 5000 (default) call service just 5 times.

    As you can see on https://github.com/emregulcan/xrmlibrary.2016/blob/master/XrmLibrary.EntityHelpers/Marketing/ListHelper.cs#L422-L462 page (yellow highlighted) "FetchData" method retrieve data with your limit value for first time and if has more records it running in a loop (while) to get all data.

    while (data.MoreRecords)
                {
                    query.PageInfo.PageNumber += 1;
                    query.PageInfo.PagingCookie = data.PagingCookie;
                    data = this.OrganizationService.RetrieveMultiple(query);
    
                    if (data != null && !data.Entities.IsNullOrEmpty())
                    {
                        foreach (var item in data.Entities)
                        {
                            name = isStatic ? ((AliasedValue)item[nameAttribute]).Value.ToString() : item.GetAttributeValue<string>(nameAttribute);
                            result.Add(membertype, new ListMemberItemDetail(item.Id, name));
                        }
                    }
                }


  • Jan Gracelin Jeno Profile Picture
    Jan Gracelin Jeno 150 on at
    RE: Get all contacts related to a marketing list.

    Using fetch to retrieve records will bring only one page.One page will have only 5000 records.So you have to retrieve all pages.

  • Suggested answer
    Emre GULCAN Profile Picture
    Emre GULCAN 2,379 on at
    RE: Get all contacts related to a marketing list.

    Hi,

    You can use XrmLibrary's "ListHelper.GetMemberList" and you can get your all members easily, it's not related static or dynamics, please see example code below;

    ListHelper listHelper = new ListHelper(_organizationService);
    var memberList = listHelper.GetMemberList(Guid.Parse("YOUR MARKETING LIST ID"));
    
    if(memberList !=null && memberList.Count > 0)
    {
       var memberListDataType = memberList.MemberType; //Account - Contact - Lead
    
       foreach (var item in memberList.Data)
       {
          Guid memberId = item.Id;
          var memberFullname = item.Name;
       }
    }


    "memberList" is a special response (ListMemberResult) and contains all data (even if 5000+) inside "Data"  property.

    You can install XrmLibrary dll files via NuGet;

    https://www.nuget.org/packages/XrmLibrary.EntityHelpers.2015/ 

    https://www.nuget.org/packages/XrmLibrary.EntityHelpers.2016/ 

    and also signed versions (for plugin/workflow assembly)

    https://www.nuget.org/packages/XrmLibrary.EntityHelpers.2015.Signed/ 

    https://www.nuget.org/packages/XrmLibrary.EntityHelpers.2016.Signed/ 

    If you don't want use any 3rd party library (in this post XrmLibrary), please look at https://github.com/emregulcan/xrmlibrary.2016/blob/master/XrmLibrary.EntityHelpers/Marketing/ListHelper.cs for related codes, you can directly copy/paste this codes in your solution.

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans