How to retrieve all the fields of entity details in Salesforce using SOQL

Step 1: First create the salesforce API. Please refer to my my previous post.
Step 2: Pass the account ids as array.. as ¬†GetAccountDetails(new string {“6ghgg687ihh”, “9hhj789899n”})

public List<Account> GetAccountDetails(string[] accountIds)
        {
            List<Account> objAccountList = new List<Account>();
            Account objAccount = new Account();
            String sQuery = string.Empty;
            String accountFieldNames = "";
            String contactFieldNames = "";
            DescribeSObjectResult describeSObjectResult = svc.describeSObject("Account");

            foreach (var item in describeSObjectResult.fields)
            {
                if (accountFieldNames == "")
                {
                    accountFieldNames = item.name;
                }
                else
                {
                    accountFieldNames += ',' + item.name;
                }
            }

            describeSObjectResult = svc.describeSObject("Contact");

            foreach (var item in describeSObjectResult.fields)
            {
                if (contactFieldNames == "")
                {
                    contactFieldNames = item.name;
                }
                else
                {
                    contactFieldNames += ',' + item.name;
                }
            }
            sQuery = "Select " + accountFieldNames + ", (Select " + contactFieldNames + " From Contacts) From Account where Id='" + accountIds[0] + "'";
            sObject[] sobjects = svc.query(sQuery).records;
            if (sobjects != null)
            {
                for (int i = 0; i < sobjects.Length; i++)
                {
                    objAccount = new Account();
                    objAccount.Id = sobjects[i].Id;
                    objAccount.AccountNumber = ((Account)sobjects[i]).AccountNumber;
                    objAccount.Name = ((Account)sobjects[i]).Name;
                    objAccount.Website = ((Account)sobjects[i]).Website;
                    objAccount.ShippingCity = ((Account)sobjects[i]).ShippingCity;
                    objAccount.ShippingCountry = ((Account)sobjects[i]).ShippingCountry;
                    objAccount.ShippingPostalCode = ((Account)sobjects[i]).ShippingPostalCode;
                    objAccount.ShippingState = ((Account)sobjects[i]).ShippingState;
                    objAccount.ShippingStreet = ((Account)sobjects[i]).ShippingStreet;
                    objAccount.BillingCity = ((Account)sobjects[i]).BillingCity;
                    objAccount.BillingCountry = ((Account)sobjects[i]).BillingCountry;
                    objAccount.BillingPostalCode = ((Account)sobjects[i]).BillingPostalCode;
                    objAccount.BillingState = ((Account)sobjects[i]).BillingState;
                    objAccount.BillingStreet = ((Account)sobjects[i]).BillingStreet;
                    objAccount.AccountSource = ((Account)sobjects[i]).AccountSource;
                    objAccount.AnnualRevenue = ((Account)sobjects[i]).AnnualRevenue;
                    objAccount.AnnualRevenueSpecified = ((Account)sobjects[i]).AnnualRevenueSpecified;
                    objAccount.Contacts = ((Account)sobjects[i]).Contacts;
                    objAccount.CreatedBy = ((Account)sobjects[i]).CreatedBy;
                    objAccount.CreatedById = ((Account)sobjects[i]).CreatedById;
                    objAccount.CreatedDate = ((Account)sobjects[i]).CreatedDate;
                    objAccount.CreatedDateSpecified = ((Account)sobjects[i]).CreatedDateSpecified;
                    objAccount.Fax = ((Account)sobjects[i]).Fax;
                    objAccount.Industry = ((Account)sobjects[i]).Industry;
                    objAccount.IsDeleted = ((Account)sobjects[i]).IsDeleted;
                    objAccount.IsDeletedSpecified = ((Account)sobjects[i]).IsDeletedSpecified;
                    objAccount.Jigsaw = ((Account)sobjects[i]).Jigsaw;
                    objAccount.JigsawCompanyId = ((Account)sobjects[i]).JigsawCompanyId;
                    objAccount.LastActivityDate = ((Account)sobjects[i]).LastActivityDate;
                    objAccount.LastActivityDateSpecified = ((Account)sobjects[i]).LastActivityDateSpecified;
                    objAccount.LastModifiedBy = ((Account)sobjects[i]).LastModifiedBy;
                    objAccount.LastModifiedById = ((Account)sobjects[i]).LastModifiedById;
                    objAccount.LastModifiedDate = ((Account)sobjects[i]).LastModifiedDate;
                    objAccount.LastModifiedDateSpecified = ((Account)sobjects[i]).LastModifiedDateSpecified;
                    objAccount.NumberOfEmployees = ((Account)sobjects[i]).NumberOfEmployees;
                    objAccount.NumberOfEmployeesSpecified = ((Account)sobjects[i]).NumberOfEmployeesSpecified;
                    objAccount.NumberofLocations__c = ((Account)sobjects[i]).NumberofLocations__c;
                    objAccount.NumberofLocations__cSpecified = ((Account)sobjects[i]).NumberofLocations__cSpecified;
                    objAccount.Owner = ((Account)sobjects[i]).Owner;
                    objAccount.OwnerId = ((Account)sobjects[i]).OwnerId;
                    objAccount.Ownership = ((Account)sobjects[i]).Ownership;
                    objAccount.Phone = ((Account)sobjects[i]).Phone;
                    objAccount.Rating = ((Account)sobjects[i]).Rating;
                    objAccount.Sic = ((Account)sobjects[i]).Sic;
                    objAccount.SicDesc = ((Account)sobjects[i]).SicDesc;
                    objAccount.Site = ((Account)sobjects[i]).Site;
                    objAccount.Type = ((Account)sobjects[i]).Type;
                    objAccountList.Add(objAccount);
                }
            }
            return objAccountList;
        }
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
This entry was posted in Salesforce and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *