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
Matt Knutson 22Matt Knutson 22 

I have a Apex Class that is no longer working

As of Winter 18' the following apex class no longer works.  I am not a developer, we do not have one on staff, nor do we have premier support so this is my last hope.  Any thoughts are graciously appreciated.  What this did is allow our customer care reps to delete leads only when doing so as part of the merge process.  Now the just get the error message in the trigger each time 'You are not authorized to delete leads'.

User-added image
jigarshahjigarshah
Matt,

Have you tried looking into Debug Logs by navigating to Setup > Debug Logs for the error? Is there a specific error message that you encounter?

Moreover, I see that only Salesforce Users with the KLC Call Centre User Profile are permitted to delete. Have you ensured that the user who is attempting to delete belongs to the said user profile?

Please verify if the respective User's profile has Delete permissions in order to be able to delete the record.
Matt Knutson 22Matt Knutson 22
@jigarshah,

The profile has the delete permission, I double checked again.  This had been working for literally years right up to the winter 18' release.  This class made it so they could only delete when doing it as part of the merge process.  Somehow it appears the code is no longer picking up that the user is doing so as part of a merge process.  I am not seeing any errors in the debug log, but it appears it is picking up that the action was not part of the merge process, even though it was below.

|VARIABLE_ASSIGNMENT|[8]|mergeOperation|false
jigarshahjigarshah
Matt,

Have you switched your org from Salesforce Classic to Lightning Experience? If yes, then this could be the reason since, the code written here checks for the presence of the keyword leadmergewizard in the context of the url and accordingly sets the mergeOperation flad to true. This url is different and could have changed in the new Lightning Experience (LEX)

Hence, the fix to this would be either of the following
  1. Switch back to Salesforce Classic. This I understand is a quick fix and may not be a great long term solution.
  2. The other thing to do here is to determine whether the merge operation is being performed through Salesforce Classic or LEX and accordingly detect the following url and set the mergeOperation flag value within the Trigger code.
Hope that helps.
Matt Knutson 22Matt Knutson 22
Jigarshah,

We are still in classic and are not using LEX at all at this time.  Could you go into a little more detail on what you mean by "detect the following url"?  Is there a specific action I need to take or is it as simple as a copy and paste of the URL in browser?

A big thanks on your efforts to assist on this!
jigarshahjigarshah
Matt,

Your current Apex class logic on line # 7 checks for the current system url and the presence of the leadmergewizard keyword in the urlbase don which the mergeOperation flag is set to true.

Can you help me understand how and when is this class executed.What steps are followed because of which the class executes? If this class is being executed due to some action being performed on a screen, check the url in the browser which should help us approach the root cause.

Hope that helps.
Matt Knutson 22Matt Knutson 22
Jigarshah,

This class executes each time the merge process is kicked off I believe.  So that when ever the customer care folks merge, they are allowed to delete.

When I attempted to do a merge, leadmergewizard was in the URL: https://na77.salesforce.com/lead/leadmergewizard.jsp.  For some reason it seems to no longer be picking that up when running the class and the error that the cannot delete comes up.

Matt