+ Start a Discussion

Account namespace was not found

Hi All,

     I am using below code to create account through api.But Iam getting this error

"The type or namespace name 'Account' could not be found (are you missing a using directive or an assembly reference?)"


Below is my sample code In this app iam sucessfully login and and execute query also.




   public void CreateAccountSample()



        Account account1 = new Account();

        Account account2 = new Account();


        // Set some fields on the account1 object. Name field is not set  


        // so this record should fail as it is a required field.  


        account1.BillingCity = "Wichita";

        account1.BillingCountry = "US";

        account1.BillingState = "KA";

        account1.BillingStreet = "4322 Haystack Boulevard";

        account1.BillingPostalCode = "87901";


        // Set some fields on the account2 object  


        account2.Name = "Golden Straw";

        account2.BillingCity = "Oakland";

        account2.BillingCountry = "US";

        account2.BillingState = "CA";

        account2.BillingStreet = "666 Raiders Boulevard";

        account2.BillingPostalCode = "97502";


        // Create an array of SObjects to hold the accounts  


        sObject[] accounts = new sObject[2];

        // Add the accounts to the SObject array  


        accounts[0] = account1;

        accounts[1] = account2;


        // Invoke the create() call  




            SaveResult[] saveResults = binding.create(accounts); 




Sounds like you're using the partner WSDL, which has no specific account definition, if you want to use strong typed objects in your code, you'll need to use the enterprise WSDL, otherwise you'll need to construct an SObject with its type property set to Account, and whatever fields you need setting in the Any, there should be samples in the API docs, and there's a download of partner WSDL samples for .NET as well.