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
Jamie GelepJamie Gelep 

Need help with VisualForce page to prevent users from deleting Leads

Here's my code I'm trying to use but I was only given the code for one user.  I don't know what changes I need to make to have this work for multiple users. I'm not a programmer and would love some help!  Thank you!


<apex:page action="{!if($User.Alias !='user1,user2,user3,user4,user5',
                    null,
                    urlFor($Action.Lead.Delete, $CurrentPage.Parameters.id, [retURL='/00Q'], true)
                    )
                    }" standardController="Lead">
   <apex:pageBlock >
     <apex:PageMessage summary="You are not allowed to delete Leads. Please contact your Field Marketing Manager for assistance." severity="Warning" strength="3"/>
     <apex:pageMessages />
   </apex:pageBlock>
</apex:page>
sandeep sankhlasandeep sankhla
Hi Jamie,

from here you can add or remove the users 
action="{!if($User.Alias !='user1,user2,user3,user4,user5',

thanks
sandeep sankhlasandeep sankhla
Hi Jamie,

you can add or remove user's alias name to prevent it...
please check adn provide the user alias name from you want to hide the deleteing...
thanks
Darshan Shah2Darshan Shah2
Hello Jamie Gelep,

Just paste below code in your page and let us know whether it works or not.

<apex:page action="{!if($User.Alias !='',
                    null,
                    urlFor($Action.Lead.Delete, $CurrentPage.Parameters.id, [retURL='/00Q'], true)
                    )
                    }" standardController="Lead">
   <apex:pageBlock >
     <apex:PageMessage summary="You are not allowed to delete Leads. Please contact your Field Marketing Manager for assistance." severity="Warning" strength="3"/>
     <apex:pageMessages />
   </apex:pageBlock>
</apex:page>

Warm Regards,
Darshan Shah
Jamie GelepJamie Gelep
Thank you.  What is the code if I want to add more than one user alias? 
 
sandeep sankhlasandeep sankhla
Hi Jamie,

You can associate one custom controller and there in action method you can simply get the all user list and check and set one boolena true false adn then you can render your message on page conditionally from there..

Thanks
Jamie GelepJamie Gelep
Sorry, I'm not a programmer and I don't understand what your answer means.  
Jamie GelepJamie Gelep
And, to confirm, the Alias Names I would be adding to this code are the SFDC users that I DO want to give the ability to delete.  All other users, not listed in the code, should get the "can't delete" message.  Is that the way the code is written?  I hope so!  Thanks.
 
Darshan Shah2Darshan Shah2
Okay Jamie,

You want users listed in code need to delete the lead.
find below code which will suffice your problem.
If there are multiple users then you just need to add userAlias in OR(||) condition shown below as underline.


<apex:page action="{!if(($User.Alias =='user1' || $User.Alias =='user2' || $User.Alias =='user3'),
                    urlFor($Action.Lead.Delete, $CurrentPage.Parameters.id, [retURL='/00Q'], true),
                    null
                    )
                    }" standardController="Lead">
   <apex:pageBlock >
     <apex:PageMessage summary="You are not allowed to delete Leads. Please contact your Field Marketing Manager for assistance." severity="Warning" strength="3"/>
     <apex:pageMessages />
   </apex:pageBlock>
</apex:page>

Warm Regards,
Darshan Shah
Brian Johnson 19Brian Johnson 19
Hello developer forum!  Hopefully someone can help.  I am using the exact same code to prevent users from deleting records in other objects (Account, Contact, Opportunity, Task) but when I click "Preview" on the Visualforce page, I get the following error:

Invalid parameter for function URLFOR
Error is in expression '{!if($User.Alias !='BJohn', null, urlFor($Action.Account.Delete, $CurrentPage.Parameters.id, [retURL='/001'], true) )}' in component <apex:page> in page preventaccountdelete

Here is the code I'm using:

<apex:page action="{!if($User.Alias !='MYNAME',
null, urlFor($Action.Account.Delete, $CurrentPage.Parameters.id, [retURL='/001'], true)
)
}"
standardController="Account">
<apex:pageBlock >
<apex:PageMessage summary="You are not allowed to delete Accounts"
severity="Warning"
strength="3"/>
<apex:pageMessages />
</apex:pageBlock>
</apex:page>

Thank you very much for any help you can provide!