Cannot implicitly convert type 'Salesforce.Common.Models.SuccessResponse' to 'string'

709    Asked by RobinRose in Salesforce , Asked on Aug 8, 2021
 I'm attempting to use this Simple console example on github as suggested in this answer here. sorry for coming here so much, I just need to make progress.

There is a link to the code that keeps throwing an error.

Error CS0029 Cannot implicitly convert type

'Salesforce.Common.Models.SuccessResponse' to 'string'

UserAccounts D:Salesforce-ResearchUserAccountsViewProgram.cs 108

enter image description here

I've compared that line with similar lines in the code:

Console.WriteLine("Creating a parent record (Account)"); dynamic a = new ExpandoObject(); a.Name = "Account from .Net Toolkit"; a.Id = await client.CreateAsync("Account", a);

I've fiddled with the line, trying all different sorts of formats, including parsing the result or parts of it to Account or string (yes I'm desperate). I've checked that it is expecting a string (well it is as Account Id is a string).

I can only assume the code is correct.


Is this correct?


If it is correct what am I supposed to do?

thanks.


edit

I've decided to go with this:

var account = new Account { Name = "Test Account" }; // account.Id = await client.CreateAsync(Account.SObjectTypeName, account); var success1 = await client.CreateAsync(Account.SObjectTypeName, account); if(account.Id == null) { Console.WriteLine(success1.Errors.ToString() + "Failed to create test record."); return; }

AND IT DOESN'T WORK


Answered by James Wilson

 CreateAsync method returns SuccessResponse if you are facing cannot implicitly convert type error. It has three properties: string Id, object Error, and string Success. So, this should work:

    var response = await client.CreateAsync("Account", a); string Id = response.Id;

Your example code worked in the past, but when you take a look at THIS COMMIT, you'll see that - thanks to wade wegner - the return type of CreateAsync is no longer string but the SuccessResponse.

 CreateAsync method returns SuccessResponse if you are facing cannot implicitly convert type error. It has three properties: string Id, object Error, and string Success. So, this should work:

    var response = await client.CreateAsync("Account", a); string Id = response.Id;

Your example code worked in the past, but when you take a look at THIS COMMIT, you'll see that - thanks to wade wegner - the return type of CreateAsync is no longer string but the SuccessResponse.



Your Answer

Interviews

Parent Categories