+ Start a Discussion
pitaboypitaboy 

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 });
SuperfellSuperfell
You might want to say what the actual problem you're having is!.
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.
pitaboypitaboy
Thanks, for your quick reply Simon.

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

pitaboypitaboy
I should also have added that the user updating the Contact info is A Self-Service User. The goal of my form is to enable a Self-Service User to update his Contact information using the web application.

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

SuperfellSuperfell
self service users can't use the API.
pitaboypitaboy
When I create the SForceService object "sfService", I'm using my Developer Login info, not the SelfServiceUser's login info, then I make the update() method call. I don't believe this is the SelfServiceUser using the API.

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 });
SuperfellSuperfell
I'm confused, are you udpating the SelfServiceUser or the Contact ?
pitaboypitaboy
At first, I was trying to update the Contact associated with the SelfServiceUser (i.e. ContactId field in the SelfServiceUser object). The original goal was to update the FirstName, LastName, Phone and Email from the Contact. Then I tried to update the SelfServiceUser field after I was unable to update the Contact fields.

Updating the Contact would be more useful seeing that it contains more information.