function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
calbright1.3916321021228982E12calbright1.3916321021228982E12 

Working with ForceClient in SalesForce.Force.dll

I am using the new Salesforce packages for .Net.  I have sucessfully authenticated with my Salesforce credentials using the following code...

var client = await GetForceClient(httpClient);
var accounts = client.QueryAsync<Account>("SELECT id, name, description FROM Account");
GetContacts(client);

When this posts I see valid access token information in the object. Then problem is that when I try to use the client to get contact information using this code:
private static async Task<object> GetContacts(ForceClient client)
    {
        try
        {
            var contacts = await client.QueryAsync<Contact>("SELECT AccountId,AssistantName,AssistantPhone,Birthdate,CreatedById,CreatedDate,Department,Description,Email,EmailBouncedDate,EmailBouncedReason,Fax,FirstName,HomePhone,Id,IsDeleted,IsEmailBounced,Jigsaw,JigsawContactId,Languages__c,LastActivityDate,LastCURequestDate,LastCUUpdateDate,LastModifiedById,LastModifiedDate,LastName,LastReferencedDate,LastViewedDate,LeadSource,Level__c,MailingCity,MailingCountry,MailingLatitude,MailingLongitude,MailingPostalCode,MailingState,MailingStreet,MasterRecordId,MobilePhone,Name,OtherCity,OtherCountry,OtherLatitude,OtherLongitude,OtherPhone,OtherPostalCode,OtherState,OtherStreet,OwnerId,Phone,ReportsToId,Salutation,SystemModstamp,Title FROM Contact");
            if (contacts == null)
            {
                Console.WriteLine("Failed to retrieve contact by query!");
            }
            Console.WriteLine("Retrieved contacts.");
            return contacts;
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            return null;
        }

    }

An exception is always thrown-- {"A task was canceled."}
Am I missing something? It seems like I should be able to make multiple calls using the same client-- and since I have to have the _accesstoken to make my calls I would seem like this is the only way I can do this.

Thank you for your help.
Chris Albright
Wade WegnerWade Wegner
Hi Chris,

Try awaiting the call to GetContacts() like this:

var contacts = await GetContacts(client);

Hope this helps!
Wade