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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

RetrieveMutipleRequest is not available in Visualstudio environment, why?

(0) ShareShare
ReportReport
Posted on by 137

I have trying to write my first CRM plug in from my visual studio 2015 which has Microsoft 365 Developer toolkit installed, and the plug in is created from the template as my screenshot below.

plugin1.png

My question is  why isn't the RetrieveMultpleRequest compiled

RetrieveMultipleRequest rmreq = new RetrieveMultipleRequest(); // not compiled

RetrieveUnpublishedMultipleRequest rmreq1 = new RetrieveUnpublishedMultipleRequest(); // the similar method of this is compiled.

I know these example codes used in CRM 4.0, Does that mean the  RetrieveMultipleRequest method is retired? then what is his replacement method.

The following is the sample plugin code I want to implement from internet : http://mileyja.blogspot.com/2011/04/instantiating-service-object-within.html

 public void Execute(IServiceProvider serviceProvider)
        {
            
            // Obtain the organization service reference.

            IPluginExecutionContext context = (IPluginExecutionContext)
               serviceProvider.GetService(typeof(IPluginExecutionContext));

            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
          

            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                // Obtain the target entity from the input parmameters.
                Entity entity = (Entity)context.InputParameters["Target"];

                if (entity.LogicalName == "contact")
                {
                    if (entity.Attributes.Contains("address1_city") == false)
                    {
                        

                        RetrieveMultipleRequest rmreq = new RetrieveMultipleRequest();
                        RetrieveMultipleResponse rmresp = new RetrieveMultipleResponse();
                        
                        
                        QueryExpression query = new QueryExpression()
                        {
                            EntityName = "systemuser",
                            ColumnSet = new ColumnSet(true),
                            Criteria = new FilterExpression
                            {
                                FilterOperator = LogicalOperator.And,
                                Conditions = 
                                {
                                    new ConditionExpression
                                    {
                                        AttributeName = "systemuserid",
                                        Operator = ConditionOperator.Equal,
                                        Values = { context.UserId.ToString() }
                                    }
                                }
                            }
                        };

                        rmreq.Query = query;
                        rmresp = (RetrieveMultipleResponse)service.Execute(rmreq);
                        Entity user = (Entity)rmresp.EntityCollection.Entities[0];

                        entity.Attributes.Add("address1_city", context.UserId.ToString() + ": " + user.Attributes["fullname"]);
                    }
                    else
                    {
                        // Throw an error, because account numbers must be system generated.
                        // Throwing an InvalidPluginExecutionException will cause the error message to be displayed in a dialog of the Web application.
                        throw new InvalidPluginExecutionException("Bad, Naughty Plug-in, Don't do that!.");
                    }
                }
            }
        }

 

*This post is locked for comments

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

    Hello,

    According to the SDK this should work - docs.microsoft.com/.../gg327661(v%3Dcrm.8)

    I would recommend to use service.RetrieveMultiple(query) instead - this is usual practice nowadays.

  • Verified answer
    David Jennaway Profile Picture
    14,065 on at

    I think you're just missing a namespace reference.

    RetrieveUnpublishedMultipleRequest is in the Microsoft.Crm.Sdk.Messages namespace, while RetrieveMultipleRequest is in the Microsoft.Xrm.Sdk.Messages namespace. Just add the following at the top of the code:

    using Microsoft.Xrm.Sdk.Messages;


  • Peter Cong Profile Picture
    137 on at

    perfect, this is correct, it works after adding Microsoft.Xrm.Sdk.Messages  

  • Verified answer
    Sreevalli Profile Picture
    3,264 on at

    Hi,

    It is not recommended to use RetrieveMultipleRequest, rather you can use RetrieveMultiple. see the modified code below. if your intention is not just to learn RetrieveMultiple, then you can switch to single retrieve as you already having record Guid, see commented code.

      QueryExpression query = new QueryExpression()
                    {
                        EntityName = "systemuser",
                        ColumnSet = new ColumnSet(true),
                        Criteria = new FilterExpression
                        {
                            FilterOperator = LogicalOperator.And,
                            Conditions =
                                    {
                                        new ConditionExpression
                                        {
                                            AttributeName = "systemuserid",
                                            Operator = ConditionOperator.Equal,
                                            Values = { context.UserId.ToString() }
                                        }
                                    }
                        }
                    };
                    
                    EntityCollection rmresp = service.RetrieveMultiple(query);
                    Entity user = rmresp.Entities[0];
                   // Entity user = service.Retrieve("systemuser", context.UserId, new ColumnSet(true));


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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans