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
bmartinez76bmartinez76 

Profile ID check script help.

Hello, I'm trying to create some code for an S-control that checks the users profile and if not an administrator it redirects them to another page.  If the user is an admin it allows them to delete otherwise it will give them a message saying "only admins can delete".  The reason I want to do it this way is because we have a group that deals with cases and I wish to give them manage case ability but not delete.  I removed the delete button from their page layout but when you click on cases you can see the del link in the view layout and i can't remove it.  I am trying to override the delete button so that only a person with an admin profile can delete a case.
 
I have so far created a redirect (below) but can't seem to find coding on how to check the users profile when they click on the link.  Can someone assist me please?
 
(admin profile ID)
00e00000006okRY
 
Code:
<html>
<body> 
<script language="JavaScript">
<!-- 
window.parent.location.href = ("https://na5.salesforce.com/500/o");
-->
</script>
</body>
</html>

 
TCAdminTCAdmin
Hello bmartinez76,

This code should get you going in the right direction.  Please let me know if you need assistance.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
<script src="/soap/ajax/10.0/connection.js"></script> 
<script type="text/javascript"> 
function delRecord(){ 
var profId = '{!$User.ProfileId}'; 
if(profId == '00e30000000fneQ'){ 
alert('allow delete'); 
} else{ 
alert('do not delete'); 
} 
} // END delServiceCall function 
</script> 
</head> 

<body onload='delRecord()'> 
</body> 
</html>

 

bmartinez76bmartinez76
This works great!  I'm not a coder so steps like this are difficult for me.  All I need to work on now is getting it to reload the page after the script runs.  I will work on that now and post if i have any issues.  Thank you for lending a hand.  I am currently trying to learn how to create S-controls, but it can be very difficult if your not use to coding.
bmartinez76bmartinez76
Does it matter which version of Salesforce we have here to run this code?  We are currently running Enterprise edition.
TCAdminTCAdmin
Bmartinez76,

With Enterprise you will have everything that you need.  It has the API enabled which will give you the ability to do all of the API calls.  These let you do everything from creating a record to deleting a record.

Professional Edition doesn't have access to the API by default so they would have to use browser manipulation to do anything.
bmartinez76bmartinez76
I was caught up on another project and had to delay this until now.  If i try the code you provided and change the profile id to the one of the system admin here it works in alerting the user, but it doesn't delete the record if a system admin is trying to delete.  I tried to make some changes but all I get is the warning about deleting then a blank page with the sidebars.  If i then go back to the case it still remains there.  Below is what I tried after doing some searchs on the community board.


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="/soap/ajax/10.0/connection.js"></script>
<script type="text/javascript">

function delRecord(){
var case = {!Case.Id}
var profId = '{!$User.ProfileId}';
if(profId == '00e70000000sY8j')

{
Sforce.Client.prototype.Delete(case);
}

else{
alert('Only Administrators can delete cases.');

window.parent.location.href = ( "/500/o—nooverride=1");

} // END delServiceCall function
</script>
</head>

<body onload='delRecord()'>
</body>
</html>

 

sfdcfoxsfdcfox
Much like in modern American schools, I'll give you an "E" for "Effort". However, there's a few problems with your code, which explains why it doesn't work. Try these changes:
 
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="/soap/ajax/10.0/connection.js"></script>
<script type="text/javascript">

function delRecord(){
var case = '{!Case.Id}' // Needs to be in quotes!
var profId = '{!$User.ProfileId}'
if(profId == '00e70000000sY8j')
{ sforce.connection.deleteIds([case]) // Be sure to use the correct syntax; see docs. window.top.location.href = '/500/o' // You don't need to override the home tab. } else { alert('Only Administrators can delete cases.') window.top.location.href = '/'+case // Don't forget to to back to the case. } } // END delServiceCall function </script> </head> <body onload='delRecord()'> </body> </html>

 
bmartinez76bmartinez76
sfdcfox, where can I find the docs you refer to in your post?  I would like to go over it so that I can learn the proper syntax. I've made the changes you suggested but still get a blank page with the sidebar.
sfdcfoxsfdcfox
http://wiki.apexdevnet.com/index.php/Apex_Wiki

I appearantly missed this, or I would have responded ages ago. My apologies. Best of luck with your development!