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
spaghetti_codespaghetti_code 

Update field in salesforce DB

Hi All,
 
Can anyone direct me of how to update field in salesforce db? This is part that I am already done:
 
-----------------------------------

sfdcLogin();

sfdc.QueryResult queryResult = null;

binding.QueryOptionsValue = new sfdc.QueryOptions();

binding.QueryOptionsValue.batchSize = 100;

binding.QueryOptionsValue.batchSizeSpecified = true;

StringBuilder sb = new StringBuilder();

sb.Append("UPDATE Contact SET IsDeleted = 'true' WHEN AccountID = '");

sb.Append(accountID + "'");

queryResult = binding.query(sb.ToString());

-----------------------------------
 
Am I missing something there? Thanks in advance.
spaghetti_codespaghetti_code

I changed my code into this:

if (SFDCLogin())

{

//create the contact object to hold our changes

sfdc.contact updateContact = new sfdc.contact ();

//need to have the id so that web service knows which contract to update

updateContact .AccountId = accountID;

//set a new value for the name property

updateContact .IsDeleted = "true";

//call the update passing an array of object

binding.update(new sfdc.sObject[] { updateContact });

}

However, I am still not being able to update the field. Can anyone help me where I am missing here? Thanks in advance.

SuperfellSuperfell
If you want to delete something, call delete. you should probably take some time to read the docs/getting started guides.
spaghetti_codespaghetti_code
Hi,
 
I thank you for your response. Actually, I don't want to delete something, but I want to update the field in the database. This is the scenario, I have an agreement, and I want to check one of my custom field within SFDC if the customer agree with that agreement, otherwise, it will keep uncheck. Thanks in advance.
SuperfellSuperfell
IsDeleted is a read only flag that indicates the soft delete status of the row. Custom fields all have names that end in __c.
spaghetti_codespaghetti_code

Hi Simon,

Sorry for being unclear here. So, here is what I am trying to do. We have a contract object with the custom field called Agreement_Executed__c by default is unchecked. When the user accept the agreement, I need to update this field to be checked. Here is what I have done:

if (SFDCLogin())

{

//create the contract object to hold our changes

sfdc.Contract updateContract = new sfdc.Contract();

//need to have the id so that web service knows which contract to update

updateContract.Id = ContractID;

//set a new value for the name property

updateContract.Agreement_Executed__c = true;

//call the update passing an array of object

binding.update(new sfdc.sObject[] { updateContract });

}

There is no error, but the field is not updated. Am I missing something here? Thanks.

SuperfellSuperfell

updateContract.Agreement_Executed__cSpecified = true;

The specified flags are a .NET ism, and apply to most scalar types, but not strings.

spaghetti_codespaghetti_code

Hi Simon,

Thank you for your response. I added 'Specified' to it, but, it still did not update the field and it is still unchecked. Am I missing something...? Thanks.

TKapTKap
I am having the exact same issue and the specified did not address the problem.
 
Do you have any insight as to why this occuring? 
 
Thank you,
Tom
SuperfellSuperfell
Post your code.
spaghetti_codespaghetti_code
Duplicate message

Message Edited by spaghetti_code on 09-14-2007 09:30 AM

spaghetti_codespaghetti_code
Hi Simon,
 
Here is the complete code:
 
=========================
 

protected bool SFDCLogin()

{

try

{

loginResult = binding.login("zzzzz@yyyyyyy.com", "xxxxxxx");

}

catch (System.Web.Services.Protocols.SoapException e)

{

// This is likley to be caused by bad username or password
Response.Write(e.Message + ", sorry, please try again....");

return false;

}

catch (Exception e)

{

// This is something else, probably communication
Response.Write(e.Message + ", so please try again....");

return false;

}

binding.Url = loginResult.serverUrl;
binding.SessionHeaderValue = new sfdc.SessionHeader();
binding.SessionHeaderValue.sessionId = loginResult.sessionId;
sfdc.
GetUserInfoResult userInfo = loginResult.userInfo;

return true;

}

=========================

if (SFDCLogin())

{

//create the contract object to hold our changes
sfdc.Contract updateContract = new sfdc.Contract();

//need to have the id so that web service knows which contract to update
updateContract.Id = ContractId;

//set a new value for the name property
updateContract.Agreement_Executed__cSpecified = true;

//call the update passing an array of object
binding.update(new sfdc.sObject[] { updateContract });

}

===============================================

Thanks.

SuperfellSuperfell
You have to set both the field you want to change, and its specified flag, e.g.

updateContract.Agreement_Executed__c = true;
updateContract.Agreement_Executed__cSpecified = true;
spaghetti_codespaghetti_code

Hi Simon,

I added that line of code, but it is still not changing the field. Can I do update using sql query instead of using binding.update() method. Thanks.

SuperfellSuperfell
No, SOQL only supports queries.

I also notice that you're not checking the returned SaveResult. As update it a batch call, its result is an array of results, you need to examine this response structure.

This is covered by the getting started samples and the api docs, which you really should read.