You need to sign in to do that
Don't have an account?
pitaboy
Update Contact Problems
I'm trying to update a Contact object yet I'm having problems doing so. I've looked through the forum and can't find anything to help. Am I missing something in my code?
QueryResult qr = sfService.query("Select Department, Email, FirstName, Id, LastName, MobilePhone, Phone, Title from Contact where Id='" + id + "'");
Contact contactObj = (Contact)qr.records[0];
contactObj.FirstName = newFirstName;
contactObj.LastName = newLastName;
contactObj.Phone = newPhone
contactObj.MobilePhone = newMobile;
contactObj.Email = newEmail;
contactObj.Department = newDepartment;
contactObj.Title = newTitle;
SaveResult[] sr = sfService.update(new sObject[] { contactObj });
QueryResult qr = sfService.query("Select Department, Email, FirstName, Id, LastName, MobilePhone, Phone, Title from Contact where Id='" + id + "'");
Contact contactObj = (Contact)qr.records[0];
contactObj.FirstName = newFirstName;
contactObj.LastName = newLastName;
contactObj.Phone = newPhone
contactObj.MobilePhone = newMobile;
contactObj.Email = newEmail;
contactObj.Department = newDepartment;
contactObj.Title = newTitle;
SaveResult[] sr = sfService.update(new sObject[] { contactObj });
Also, there's no need to query the record to update it, you appear to have everything you need (the Id, and the fields you want to update), just create an Contact and populate the fields you want to update and call update.
I'm trying to update a Contact through API 6.0 and C#. However the Contact information is not being updated. The SaveResult object that is returned after making the update() method call is returning true which should signal that the Contact has been updated. However, the Contact itself is not being updated.
I've changed my code to create a new Contact with the same Id and the fields that require updating and I'm still having the same difficulties of the Contact not being updated eventhough the SaveResult indicate that it has been updated.
Contact contactObj = new Contact();
contactObj.Id = id;
contactObj.FirstName = newFirstName;
contactObj.LastName = newLastName;
contactObj.Phone = newPhone
contactObj.MobilePhone = newMobile;
contactObj.Email = newEmail;
contactObj.Department = newDepartment;
contactObj.Title = newTitle;
SaveResult[] sr = sfService.update(new sObject[] { contactObj });
if (sr[0].success)
{
ResultLabel.Text = "Contact updated";
}
else
{
ResultLabel.Text = sr[0].errors[0].message;
}
Message Edited by pitaboy on 08-18-2005 12:50 PM
Is this the casue of my problems? If so, is there any way for a Self-Servie User to update his/her Contact information?
Message Edited by pitaboy on 08-18-2005 12:29 PM
Also, I'm a little confused. Why are the Email, FirstName, LastName, Username described as "updatable" if I can't update a SelfServiceUser info?
SforceService sfService = new SforceService();
// Invoke the login call and save results in LoginResult
LoginResult lr = sfService.login(usr,pwd);
// Reset the SOAP endpoint to the returned server URL
sfService.Url = lr.serverUrl;
// Create a new session header
// Add the session ID returned from the login
sfService.SessionHeaderValue = new SessionHeader();
sfService.SessionHeaderValue.sessionId = lr.sessionId;
//Update the contactObj code here
SaveResult[] sr = sfService.update(new sObject[] { contactObj });
Updating the Contact would be more useful seeing that it contains more information.