Winter 16 Release – “new” Notes

As part of the Winter 16 release, in addition to the lightning experience Salesforce rolled out some new Notes. I enabled the new notes, however we are keeping salesforce classic experience for now. I was hoping to get some help on the following questions. These are in the “Notes” list on the relevant pages (Lead, Contact, Account, Opportunity). I went ahead and hide the old Notes and Attachments section, and added the Notes to the layout. They are stored as ContentDocument object.

I had a few questions:

  1. How can I ensure these notes are being associated to the Account/Contact during a lead conversion event. I see this happening sometimes but not others, in fact I can view the note browsed to via the Files section of a Chatter User page, that its associated to a Lead but when I click that lead it mentions “Lead Converted”.

  2. How can I query these using SOQL?


When I go into Developer Console and execute these queries:

SELECT COUNT(Id) FROM ContentDocument -> yields 3

SELECT COUNT(Id) FROM ContentDocument WHERE Id != '069o0000000HQVm' > yields 3

SELECT COUNT(Id) FROM ContentDocument WHERE Id = '069o0000000HQVm' > yields 1

I think this is related to some type of permission issue. If I explicitly share a note via the UI with myself (I am a SysAdmin but not Note Creator) I can query the note via SOQL however if I don’t have permission I can’t. Perhaps the solution is to create a default sharing permission.

Answer

With regards to the SOQL query and accessing all the ContentDocument records.

As you found, if you run a SOQL query against all the ContentDocument records, you get 3 records back (in your example case). But if you make a SOQL query for an explicit ContentDocument ID that doesn’t come back in the first set of results you can access a 4th record.

I believe the difference comes from the selected query execution plan applying the record sharing rules. When you do the SOQL query without the where clause the query plan with the lowest cost has the Sharing type. In the documentation this is described as:

The query will use an index based on the sharing rules associated with the user who is executing the query. If there are sharing rules that limit which records that user can access, Salesforce can use those rules to optimize the query.

So, if the sharing plan has the lowest cost it will be used, and will only return records that have been shared to the current user.

Have a look at Using the with sharing or without sharing Keywords. If you can run your SOQL query in a without sharing context the sharing plan shouldn’t come into affect and restrict the records that are returned.

To get the same level of access via the API’s you should alter the user permissions:

Sharing
For most API calls, data that is outside of the logged-in user’s sharing model is not returned. Users are granted the most permissive access that is available to them, either through organization-wide defaults or manual record sharing, just as in the application.

User Permissions that Override Sharing

  • View All—Users can view all records associated with this object, regardless of sharing settings.
  • Modify All—Users can read, edit, delete, transfer, and approve all records associated with this object, regardless of sharing settings.
  • Modify All Data—users can read, edit, delete, transfer, and approve all records regardless of sharing settings. This permission is not an object-level permission, unlike “View All” and “Modify All.”

To protect the security of your data, give the logged-in user only the permissions needed to successfully execute all the calls made by the application. For large integration applications, “Modify All Data” may speed up call response times.

Attribution
Source : Link , Question Author : Brad Ruderman , Answer Author : Daniel Ballinger

Leave a Comment