Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- .NET Development
- :
- Update Self-Service User Record
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Update Self-Servi ce User Record
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-17-2012 10:08 AM
I would like to update a Self-Service User record via an OM when the related contact record is updated. The below code is generating the following error: Object reference not set to an instance of an object.
I appreciate the help!
for (int i = 0; i < contacts.Length; i++)
{
EditContactNotification.ContactNotification notification = contacts[i];
EditContactNotification.Contact contact = (EditContactNotification.Contact)notification.sObj ect;
EnterpriseWebReference.QueryResult qr = null;
try
{
qr = binding.query("SELECT Id FROM SelfServiceUser WHERE ContactId = " + contact.Id);
}
catch (System.Exception e)
{
Console.WriteLine("Query didn't work " + e.Message);
}
if (qr.size > 0)
{
EnterpriseWebReference.sObject[] records = qr.records;
for (int x = 0; x < records.Length; x++)
{
EnterpriseWebReference.SelfServiceUser var = ((EnterpriseWebReference.SelfServiceUser)records[x ]);
EnterpriseWebReference.SelfServiceUser ssu = new EnterpriseWebReference.SelfServiceUser();
ssu.Id = var.Id;
ssu.ContactId = contact.Id;
ssu.FirstName = contact.FirstName;
ssu.LastName = contact.LastName;
ssu.Username = contact.Email;
ssu.Email = contact.Email;
EnterpriseWebReference.SaveResult[] saveResults = binding.update(new EnterpriseWebReference.sObject[] { ssu });
}
Solved! Go to Solution.
Re: Update Self-Servi ce User Record
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-17-2012 01:06 PM
Re: Update Self-Servi ce User Record
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-17-2012 01:43 PM
I've refactored my code a bit and I am no longer receiving an error; however, my SSU is not updating either.
Here is my current code. This is my first C# web service so I'm not sure how best to debug the code. I'm not sure if I'm getting a result from the query or not. Any suggestions you have are appreciated!
EditContactNotification.ContactNotification[] contacts = notifications1.Notification;
for (int i = 0; i < contacts.Length; i++)
{
EditContactNotification.ContactNotification notification = contacts[i];
EditContactNotification.Contact contact = (EditContactNotification.Contact)notification.sObj ect;
try
{
EnterpriseWebReference.QueryResult qr = null;
qr = binding.query("SELECT Id FROM SelfServiceUser WHERE ContactId = " + contact.Id);
if (qr.size > 0)
{
EnterpriseWebReference.sObject[] records = qr.records;
for (int x = 0; x < records.Length; x++)
{
EnterpriseWebReference.SelfServiceUser var = ((EnterpriseWebReference.SelfServiceUser)records[x ]);
EnterpriseWebReference.SelfServiceUser ssu = new EnterpriseWebReference.SelfServiceUser();
ssu.Id = var.Id;
ssu.ContactId = contact.Id;
ssu.FirstName = contact.FirstName;
ssu.LastName = contact.LastName;
ssu.Username = contact.Email;
ssu.Email = contact.Email;
try
{
EnterpriseWebReference.SaveResult[] saveResults = binding.update(new EnterpriseWebReference.sObject[] { ssu });
}
catch (System.Exception e)
{
Console.WriteLine("Update didn't work " + e.Message);
}
}
}
}
catch (System.Exception e)
{
Console.WriteLine("Query didn't work " + e.Message);
}
}
EditContactNotification.notificationsResponse response = new EditContactNotification.notificationsResponse();
response.Ack = true;
return response;
}
Re: Update Self-Servi ce User Record
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-17-2012 04:52 PM
Re: Update Self-Servi ce User Record
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-18-2012 07:19 AM
Can you send me an example of how I might add the additional logging? Will I see the log information on the OM Delivery Status screen?
Thank you
Re: Update Self-Servi ce User Record
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-19-2012 08:59 AM
I still don't know how to debug my code but I figured out the issue. I was setting the contact Id in my original update code and once I took that out everything started working. Here is my functioning code for anyone trying to update a Self Service User account in the future.
EditContactNotification.ContactNotification[] contacts = notifications1.Notification;
for (int i = 0; i < contacts.Length; i++)
{
EditContactNotification.ContactNotification notification = contacts[i];
EditContactNotification.Contact contact = (EditContactNotification.Contact)notification.sObj ect;
try
{
EnterpriseWebReference.QueryResult qr = null;
qr = binding.query("SELECT Id FROM SelfServiceUser WHERE ContactId = '" + contact.Id + "'");
if (qr.size > 0)
{
EnterpriseWebReference.sObject[] records = qr.records;
for (int x = 0; x < records.Length; x++)
{
EnterpriseWebReference.sObject ssu2Update = qr.records[x];
EnterpriseWebReference.SelfServiceUser ssu = new EnterpriseWebReference.SelfServiceUser();
ssu.Id = ssu2Update.Id;
ssu.FirstName = contact.FirstName;
ssu.LastName = contact.LastName;
ssu.Username = contact.Email;
ssu.Email = contact.Email;
try
{
EnterpriseWebReference.SaveResult[] saveResults = binding.update(new EnterpriseWebReference.sObject[] { ssu });
}
catch (System.Exception e)
{
Console.WriteLine("Update didn't work " + e.Message);
}
}
}
}
catch (System.Exception e)
{
Console.WriteLine("Query didn't work " + e.Message);
}
}
EditContactNotification.notificationsResponse response = new EditContactNotification.notificationsResponse();
response.Ack = true;
return response;

