You need to sign in to do that
Don't have an account?

Why have database rows not been inserted when the debug log says they have?
I have code that creates CaseShare records for the case based on some criteria from another class.
The code that creates the CaseShare is called both on update and creation of the case. It works smoothly when the case is updated, but not when it's created. When attempting to debug my issue I got confused because the debug logs apparently showed that the records were being inserted. In fact, the debug logs show the same exact things for when the case is inserted (the DML doesn't work then) as when the case is updated (the DML does work then).
Here is the debug log for both when the case is created (DML doesn't work then) and when the case is updated (DML does work) line 55 is where my insert is happening:
Additionally, here's the code that does the insert:
The code that creates the CaseShare is called both on update and creation of the case. It works smoothly when the case is updated, but not when it's created. When attempting to debug my issue I got confused because the debug logs apparently showed that the records were being inserted. In fact, the debug logs show the same exact things for when the case is inserted (the DML doesn't work then) as when the case is updated (the DML does work then).
Here is the debug log for both when the case is created (DML doesn't work then) and when the case is updated (DML does work) line 55 is where my insert is happening:
USER_DEBUG|[54]|DEBUG|Value of csShareList: (CaseShare:{CaseAccessLevel=Edit, CaseId=500180000050EsoAAE, UserOrGroupId=005E0000004JDY4IAO}, CaseShare:{CaseAccessLevel=Edit, CaseId=500180000050EsoAAE, UserOrGroupId=005E0000000dNNWIA2}, CaseShare:{CaseAccessLevel=Edit, CaseId=500180000050EsoAAE, UserOrGroupId=005E0000000dBqjIAE}, CaseShare:{CaseAccessLevel=Edit, CaseId=500180000050EsoAAE, UserOrGroupId=005E0000005aSlXIAU}) 00:53:58.516 (755158871)|SYSTEM_METHOD_EXIT|[54]|System.debug(ANY) 00:53:58.516 (755161876)|STATEMENT_EXECUTE|[55] 00:53:58.516 (755228490)|DML_BEGIN|[55]|Op:Insert|Type:CaseShare|Rows:4 00:53:58.516 (755248812)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:20 00:53:58.516 (825013969)|DML_END|[55]
Additionally, here's the code that does the insert:
if (!csShareList.isEmpty()){ System.debug('Value of csShareList: ' + csShareList); insert (csShareList); }
Only queue members and their direct reports can view or take ownership of [those] cases.
http://resources.docs.salesforce.com/198/13/en-us/sfdc/pdf/salesforce_case_implementation_guide.pdf#page=21
Here are two exceptions I learned about from this experience.
Other users can view the case if they have 'view all' on the object level or are in role hierarchy above someone with 'view all.'
The calculation for this specific sharing event happens when you change or initially set the owner to a queue but will not be calculated in for updates to the record that do not change the ownership from a user to a queue, or from one queue to another.
See http://salesforce.stackexchange.com/questions/117529/why-have-database-rows-not-been-inserted-when-the-debug-log-says-they-have/117556#117556 for more detail.
All Answers
try
{
insert(csShareList);
}
catch (exception ex)
{ system.debug(ex.message());
}
You may catch the exception this way.
Updated Debug file:
Updated code:
Updated Debug File:
1. By querying the CaseShares related to the case I just inserted.
2. I pressed the "Sharing" button on the case record to view the case shares
3. I tried to view the record as one of the users I attempted to share it with
On create, the query shows no CaseShare records with the users the code is sharing with, the sharing button also shows no CaseShare records with the users the code is sharing with, and the user gets insufficient access when trying to access the record.
However, upon edit, the query shows the CaseShare records with the users the code is sharing with, the sharing button also shows the CaseShare records with the users the code is sharing with, and the user gets is able to view the record when trying to access the it.
Only queue members and their direct reports can view or take ownership of [those] cases.
http://resources.docs.salesforce.com/198/13/en-us/sfdc/pdf/salesforce_case_implementation_guide.pdf#page=21
Here are two exceptions I learned about from this experience.
Other users can view the case if they have 'view all' on the object level or are in role hierarchy above someone with 'view all.'
The calculation for this specific sharing event happens when you change or initially set the owner to a queue but will not be calculated in for updates to the record that do not change the ownership from a user to a queue, or from one queue to another.
See http://salesforce.stackexchange.com/questions/117529/why-have-database-rows-not-been-inserted-when-the-debug-log-says-they-have/117556#117556 for more detail.