Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7601767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:14:39+00:00 2026-05-30T23:14:39+00:00

I am creating a simple console Application in .Net to create a New Account

  • 0

I am creating a simple console Application in .Net to create a New Account in CRM.For that I am using Main Data WebService and it also created but my question is that i have to set Parent Customer in Account and For that i have to set parentcustomerid in that but i am not getting how can i set it..My code is below.

   namespace ConsoleWebService
   {
      class MainDataService
      {
         static void Main(string[] args)
         {
           Console.WriteLine("New Account GUID="+CreateAccount("Server","New Account"));
           Console.ReadKey();
          }

         private static string CreateAccount(string organizationName, string accountName)
         {
           try
           {

            CrmSdk.CrmService myCrm = new CrmSdk.CrmService();
            myCrm.Url = GetCrmServiceForOrganization(organizationName);
            CrmSdk.CrmAuthenticationToken myToken = new CrmSdk.CrmAuthenticationToken();
            myToken.AuthenticationType = 0;
            myToken.OrganizationName = organizationName;
            myCrm.CrmAuthenticationTokenValue = myToken;
            myCrm.Credentials = System.Net.CredentialCache.DefaultCredentials;
            CrmSdk.account newAccount = new CrmSdk.account();

            newAccount.name = accountName;
            newAccount.address1_country = "India";
            newAccount.address1_city = "Mumbai";

            Guid newAccountId = myCrm.Create(newAccount);
            return newAccountId.ToString();
          }
          catch (System.Web.Services.Protocols.SoapException soapEx)
         {
            Console.WriteLine("SOAP exception: " + soapEx.Detail.InnerText + " " + soapEx.ToString());
            return soapEx.Detail.InnerText + "  " + soapEx.ToString();
          }
         catch (Exception ex)
         {
            Console.WriteLine("General exception: " + ex.ToString());
            return "General exception: " + ex.ToString();
         }

    }
    private static string GetCrmServiceForOrganization(string organizationName)
    {
        string urlResult = "";
        CrmSdk.Discovery.CrmDiscoveryService myCrm = new CrmSdk.Discovery.CrmDiscoveryService();

        myCrm.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
        CrmSdk.Discovery.RetrieveOrganizationsRequest myRequest = new CrmSdk.Discovery.RetrieveOrganizationsRequest();

        CrmSdk.Discovery.RetrieveOrganizationsResponse myResponse = (CrmSdk.Discovery.RetrieveOrganizationsResponse)myCrm.Execute(myRequest);
        foreach (CrmSdk.Discovery.OrganizationDetail tDetail in myResponse.OrganizationDetails)
        {
            Console.WriteLine("Organization = " + tDetail.OrganizationName);
            if (String.Compare(tDetail.OrganizationName, organizationName, true) == 0)
            {
                return tDetail.CrmServiceUrl;
            }
        }
        return urlResult;

    }

}

}

Here I can create the new account using above code but i want to set the parent custome in Account so how can i set?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:14:40+00:00Added an answer on May 30, 2026 at 11:14 pm

    Try this:

    Lookup parentAccount = new Lookup();
    parentAccount.type = EntityName.account.ToString();
    parentAccount.Value = new Guid("GUID of The Parent Account");
    newAccount.parentaccountid = parentAccount;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a simple .NET console application where I want to save a file
I have a server application (singleton, simple .NET console application) that talks to a
I'm creating a console app and using a switch statement to create a simple
Hello I am creating a simple console application in vb.net in order to convert
I have a long-running console-based application Sender that sends simple text to STDOUT using
Was creating a simple console application to do some prototyping and was shocked to
I am using Visual Studio 2008 Express and I tried creating a simple console
I'm creating a simple API that creates typed classes based on JSON data that
I am creating a simple application with Django. I realized that I am doing
I am creating simple console application where I need to load RTF file to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.