Search code examples
c#dynamics-crmdynamics-crm-onlinedynamics-crm-365

Account with Id = [ID] does not exist


I am trying to retrieve my own name filed from dynamics CRM but I keep getting this message during the retrieve. (the code successfully gives me back my user id with the WhoAmIRequest) System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault] Account with Id = [ID] does not exist.

   IOrganizationService oServiceProxy;
            try
            {
                //Create the Dynamics 365 Connection:
                CrmServiceClient oMSCRMConn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient("AuthType=Office365;Username=_username;Password=_password;URL=https://hrrevuat.crm4.dynamics.com/;");

                //Create the IOrganizationService:
                oServiceProxy = (IOrganizationService)oMSCRMConn.OrganizationWebProxyClient != null ?
                        (IOrganizationService)oMSCRMConn.OrganizationWebProxyClient :
                        (IOrganizationService)oMSCRMConn.OrganizationServiceProxy;
                if (oServiceProxy != null)
                {


                    //Get the current user ID:
                    Guid userid = ((WhoAmIResponse)oServiceProxy.Execute(new WhoAmIRequest())).UserId;



                    if (userid != Guid.Empty)
                    {
                        Console.WriteLine("Connection Successful!");
                        oServiceProxy.Retrieve("account", userid, new ColumnSet("name"));
                    }
                }
                else
                {
                    Console.WriteLine("Connection failed...");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error - " + ex.ToString());
            }

Thanks In Advance!


Solution

  • the userid you get from a WhoAmIRequest belongs to systemuser entity, not to account entity.

    oServiceProxy.Retrieve("systemuser", userid, new ColumnSet("fullname"));