[SalesForce] Insufficient Privileges when trying to view all Activity History

The Problem

We're experiencing a problem where users are getting an "Insufficient Privileges" message when using an <apex:commandButton> to view Activity History. The users are the Lead owners.

The Setup

We use a Visualforce wrapper for the Lead, embedding the standard layouts with <apex:detail inlineedit="true"/>. After this we have custom related lists, including one for Activity History that only shows users their own activities.

Relevant VF:

<apex:pageBlock title="Activity History" id="myActivities">
        <apex:pageBlockButtons location="top">
            <apex:commandButton value="View All" 
              action="{!URLFOR($Action.Activity.ViewAll, Lead.Id)}"/>
        </apex:pageBlockButtons>
   // Other code
</apex:pageBlock>

When a user clicks this "View All" button, they get the following message:

Insufficient Privileges
You do not have the level of access necessary
to perform the operation you requested. Please contact the owner of
the record or your administrator if access is necessary

Debugging

If I add the standard Activity History related list back to the page layout then my custom button works. As soon as I remove the standard related list my button breaks again. Inspecting the URL the two buttons generate did not yield much, either:

The standard button uses the following JavaScript in the onclick event:

navigateToUrl('https://cs2.salesforce.com/ui/core/activity/ViewAllActivityHistoryPage?retURL=https%3A%2F%2Fc.cs2.visual.force.com%2Fapex%2FviewLead%3Fid%3DredactedLeadId%26sfdc.override%3D1&id=redactedLeadId','RELATED_LIST','all');

The link generated by {!URLFOR($Action.Activity.ViewAll, Lead.Id)}:

https://cs2.salesforce.com/ui/core/activity/ViewAllActivityHistoryPage?retURL=https%3A%2F%2Fc.cs2.visual.force.com%2Fapex%2FviewLead%3Fid%3DredactedLeadId&id=redactedLeadId

I can also replicate this in my dev org. Steps to replicate:

  1. Create/assign a user to the Standard User profile.
  2. Create/assign a Lead to the test user.
  3. Ensure the standard related list is on the page layout.
  4. Login as the test user.
  5. Record a completed Activity.
  6. Verify the test user can follow the View All Activity History button.
  7. Login as an Admin. Remove the Activity History standard related list.
  8. Login as the test user.
  9. Try to navigate to https://[instance].salesforce.com/ui/core/activity/ViewAllActivityHistoryPage?id=[lead], replacing [instance] and [lead] with appropriate values.
  10. Receive Insufficient Privileges error.

Edit

  • The View All Activity page is the standard Salesforce page and is not overridden at all.
  • Trying to navigate directly to https://cs2.salesforce.com/ui/core/activity/ViewAllActivityHistoryPage?id=[lead] fails when the related list is hidden.

Update 2013-Dec-19

It turns out that this happens even with the default System Admin profile.

Best Answer

I can replicate the same thing that you are observing.

I have a "workaround". I was able to reverse engineer the Go to List >> links on the related list when there are more than the default number in the list (more than 5 for me) on the page.

gotolist

I built the following URL:

https://na15.salesforce.com/007?id=00Qi0000002djnG&rlid=RelatedHistoryList&closed=1

The rlid parameter specifies the related list.
The id parameter specifies the Id of the Lead.

This isn't as good as directly accessing the built-in $Action.Activity.ViewAll, of course, and it looks like you probably found a defect, but maybe you can use this in the mean time. It does work when the related list is not on the page layout.

Related Topic