You need to sign in to do that
Don't have an account?
spaghetti_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.
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.
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.
updateContract.Agreement_Executed__cSpecified = true;
The specified flags are a .NET ism, and apply to most scalar types, but not strings.
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.
Message Edited by spaghetti_code on 09-14-2007 09:30 AM
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.
updateContract.Agreement_Executed__c = true;
updateContract.Agreement_Executed__cSpecified = true;
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.
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.