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
SennahSennah 

Database.SaveResult does not contain object ID

Hi community,

 

I am experiencing a very strange problem here: When updating the isActive flag on a User I can not getId() for the failed objects.

Here's the content of my resultSet:

 

 

result: 

(Database.SaveResult
[getErrors=(Database.Error
[getFields=();getMessage=cannot inactivate default web-to-lead user;
getStatusCode=system.StatusCode.UNKNOWN_EXCEPTION;]);
getId=null;
isSuccess=false;], 

Database.SaveResult
[getErrors=();
getId=005A0000000GfeHIAS;
isSuccess=true;])

 

 

You can see that the first user errors, but the Id is null.

The second user processes and it returns the Id just fine.

 

Here's my Database operation:

 

 

Database.SaveResult[]  result = Database.Update(userList,false);
System.debug('result: ' + result);

 

 

And two btws.:

1. The Documentation states that it is not possible to set the active flag via the API but I could do this in me DE!?

2. Why does the error code says "Unknown Exception", although it prints me an error message?

 

Thankfully for any hints,

 

//Hannes

Best Answer chosen by Admin (Salesforce Developers) 
ReidCReidC

Which User doc are you looking at?  The one I found -- above -- shows it as updatable and I didn't see another one.  I'm probably just looking in the wrong place.

 

So I went through and did a little testing to be sure I was seeing you're error.  When I code in Java, and I attempt to deactivate the default web-to-lead user, I get the same error.  it also shows the same Unknown Exception.  I can check on that but to be clear I don't expect that message to change anytime soon. 

 

Double checking the docs around SaveResult, you see that you can trust that your save result array is in the same order as the sobjects you sent in:

 

"The update() call returns an array of SaveResult objects. Each element in the SaveResult array corresponds to the sObject[] array passed as the sObjects parameter in the update() call. For example, the object returned in the first index in the SaveResult array matches the object specified in the first index of the sObject[] array."

 

From http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_update_saveresult.htm

 

So what I've done is to iterate through all save results looking for failures.  When I find it, I get the same sobject by index and associate the two records.  You can see an example of how I've done this as part of Cloud Converter (not a SFDC/Labs project) (and you should feel free to laugh at my code):

 

http://code.google.com/p/force-com-cloud-converter/source/browse/trunk/force-com-cloud-converter-old-2010-01-07/src/java/com/modelmetrics/common/sforce/dao/SalesforceDAO.java#234

 

Side note: I wrote the basic Salesforce DAO lib shortly after I joined the ecosystem in 2k7 and still use portions of it today when I need to work with Java. 

 

Anyway, FWIW, that's how I would tackle the problem as you've described it to me.  HTH.

 

All Answers

ReidCReidC
ReidCReidC

Re: Active flag -- from here:

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_user.htm

 

Indicates whether the user has access to log in (true) or not (false). You can modify a User's active status from the Salesforce.com user interface or via the API.

 

Re: UNKNOWN EXCEPTION when it appears to be known --- ok you got me on that one. :-)  Have no idea.

SennahSennah

Hi Reid,

 

thank you for this information.

 

Well, it is late here, so I will not take you into an discussion about how much sense it make _not_ to have the ID of errored SaveResult objects available ;)

 

Now, what to you suggest, how should I handle the failed records properly? My idea was to collect all failed items and send a nice mail to the administrators. But now that I don't have the ID available that email wouldn't make much sense.

 

Can you make sure to follow up on the Unknown Exception thing internally?

 

Regarding the documentation on deactivating users, it says:

 

 

You can deactivate a User in the Salesforce.com user interface; and you can deactivate or disable a Customer Portal  or partner portalUser in the Salesforce.com user interface or the API.

 

I am not a pro in English punctuation, but this sounds to me like, you can deactivate Salesforce Platform Users (only) via the UI and Portal users also via the API - doesn't it?

 

Also; I was checking with my local Salesforce partner and he was very surprised to hear that I was actually able to change the isActive flag via Apex, because he tried to do this for a customer a while ago and it didn't worked out.

 

Cheers,

//Hannes

ReidCReidC

Hey Hannes,


Thanks as always for the detailed reply.  Can you shoot me the link where you found that quote?  I'm probably missing something but I'm happy to do some research.

 

Thanks!

 

Reid

 

SennahSennah

It's from the User Object documentation.

 

Curious about your findings.

ReidCReidC

Which User doc are you looking at?  The one I found -- above -- shows it as updatable and I didn't see another one.  I'm probably just looking in the wrong place.

 

So I went through and did a little testing to be sure I was seeing you're error.  When I code in Java, and I attempt to deactivate the default web-to-lead user, I get the same error.  it also shows the same Unknown Exception.  I can check on that but to be clear I don't expect that message to change anytime soon. 

 

Double checking the docs around SaveResult, you see that you can trust that your save result array is in the same order as the sobjects you sent in:

 

"The update() call returns an array of SaveResult objects. Each element in the SaveResult array corresponds to the sObject[] array passed as the sObjects parameter in the update() call. For example, the object returned in the first index in the SaveResult array matches the object specified in the first index of the sObject[] array."

 

From http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_update_saveresult.htm

 

So what I've done is to iterate through all save results looking for failures.  When I find it, I get the same sobject by index and associate the two records.  You can see an example of how I've done this as part of Cloud Converter (not a SFDC/Labs project) (and you should feel free to laugh at my code):

 

http://code.google.com/p/force-com-cloud-converter/source/browse/trunk/force-com-cloud-converter-old-2010-01-07/src/java/com/modelmetrics/common/sforce/dao/SalesforceDAO.java#234

 

Side note: I wrote the basic Salesforce DAO lib shortly after I joined the ecosystem in 2k7 and still use portions of it today when I need to work with Java. 

 

Anyway, FWIW, that's how I would tackle the problem as you've described it to me.  HTH.

 

This was selected as the best answer
SennahSennah

Hi Reid,

 

many thanks for your help with this. So I guess I will do it the way that you described.

Do you think there is a slight chance that getID() will work with failed records as well? I still can't understand why it does not. It just makes no sense to me.

 

The quoted part from my previous posting is from http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_user.htm section "Deactivate user". It does not explicitly say that you can't as well as it does not say that you can.

 

Cheers,

//Hannes