+ Start a Discussion
Rodolfo CalvoRodolfo Calvo 

Salesforce.Common.ForceException

Hello team, 

I am developing a Cleansing App, I achived to log in with 0Auth2 to salesforce successfully. But at the moment to make my first query the catch statement showed me an error. 

There is an unexpected error: System.AggregateException: Se han producido uno o varios errores. ---> Salesforce.Common.ForceException: The requested resource does not exist en Salesforce.Common.ServiceHttpClient.<HttpGetAsync>d__1`1.MoveNext() --- Fin del seguimiento de la pila de la excepción interna --- en System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) en System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) en System.Threading.Tasks.Task.Wait() en OAuthDemoMVC5.Controllers.SalesforceController.sqlQuery() en C:\Users\RodolfoPC\Desktop\SFAuth0\Auth0\src\DemoMVC5\OAuthDemoMVC5\Controllers\SalesforceController.cs:línea 58 ---> (Nº de excepción interna 0) Salesforce.Common.ForceException: The requested resource does not exist en Salesforce.Common.ServiceHttpClient.<HttpGetAsync>d__1`1.MoveNext()<---

This is my statement: 
 
var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);
                Task<QueryResult<dynamic>> results = client.QueryAllAsync<dynamic>("SELECT id, FirstName, LastName, Email FROM Contact");
                results.Wait();

                var contacts = results.Result.Records;

                foreach (var contact in contacts)
                {
                    //Console.WriteLine(contact.FirstName);
                    //ViewData["Contacts"] = contact.FirstName.toString();
                    ViewBag.conTShow = contact.FistName.toString();

                }
            }
            catch(Exception e)
            {
                //Console.Write("There is an error: " + e.ToString().Trim());
                ViewBag.conError = "There is an unexpected error: " + e.ToString().Trim();
            }

Can someone help me with this issue please?
Thansk and regards!
Best Answer chosen by Rodolfo Calvo
Rodolfo CalvoRodolfo Calvo
When I use one of them separatly this error shows. I install the dependencies of course. Could not load type 'WebServerOAuthFlow.WebApiApplication'. from this (https://github.com/developerforce/Force.com-Toolkit-for-NET/tree/master/samples/WebServerOAuthFlow) do you know what I am doing wrong? 

All Answers

Andy BoettcherAndy Boettcher
Does the user you're using to authenticate have access to the Contact object?
Rodolfo CalvoRodolfo Calvo
I guess that would be problem. Look the auth I just did. 

 
public void sqlQuery() {
            try
            {
                var auth = new Salesforce.Common.AuthenticationClient();

                var instanceUrl = auth.InstanceUrl;
                var accessToken = auth.AccessToken;
                var apiVersion = auth.ApiVersion;

                auth.InstanceUrl = "https://na22.salesforce.com/";
                //auth.AccessToken = "https://na22.salesforce.com/services/oauth2/token";
                auth.AccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
                auth.ApiVersion = "21.0";



                var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);
                Task<QueryResult<dynamic>> results = client.QueryAllAsync<dynamic>("SELECT id, FirstName, LastName, Email FROM Contact");
                results.Wait();

                var contacts = results.Result.Records;

                foreach (var contact in contacts)
                {
                    //Console.WriteLine(contact.FirstName);
                    //ViewData["Contacts"] = contact.FirstName.toString();
                    ViewBag.conTShow = contact.FistName.toString();

                }
            }
            catch(Exception e)
            {
                //Console.Write("There is an error: " + e.ToString().Trim());
                ViewBag.conError = "There is an unexpected error: " + e.ToString().Trim();
            }
        }

This is the whole method I did. 

Regards and thanks Andy. 
Andy BoettcherAndy Boettcher
That's my question Rodolfo - does the user/profile you're using to authenticate have access to the Contact object?  Can you log into Salesforce as that user (not via API - logging in via browser) and execute that same query in Developer Console?
Rodolfo CalvoRodolfo Calvo
It does, it has access to it. In console developer, I needed to change some things of course, but in developer console it worked fine. It shows me the information. That’s why I don’t understand. 
Andy BoettcherAndy Boettcher
If you dump results.Result.Records to console or debug, what does it look like?
Rodolfo CalvoRodolfo Calvo
In
Task<QueryResult<dynamic>> results = client.QueryAllAsync<dynamic>("SELECT name, lastname, phone, email, birthdate FROM contact limit 10");

It jumps directly to catch statement. It seems is not reading the code, I am not using more things than this. Of course the 
using Salesforce.Force;
using System.Threading.Tasks;
using Salesforce.Common.Models;

Actually, please would you have a template of tutorial about what I need to do? I would like to make a data cleansing. Do you think it is possible?
 
Andy BoettcherAndy Boettcher
Is this in Java?
Rodolfo CalvoRodolfo Calvo
No, it is in Asp.net c#
Rodolfo CalvoRodolfo Calvo
I do, actually. I am using the authentication with it and trying to make all this with that. For example look at this: 
https://github.com/developerforce/Force.com-Toolkit-for-NET the Creating the ForceClient is the same I am using in my app but does not work. 
Rodolfo CalvoRodolfo Calvo
When I use one of them separatly this error shows. I install the dependencies of course. Could not load type 'WebServerOAuthFlow.WebApiApplication'. from this (https://github.com/developerforce/Force.com-Toolkit-for-NET/tree/master/samples/WebServerOAuthFlow) do you know what I am doing wrong? 
This was selected as the best answer