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
jgrenfelljgrenfell 

S-Control and Permission to run a SoQL Query

I have an S-control that just takes the id that's passed to it (it's the Id of a new record just saved), performs a SoQL query and then redirects the user to a related record.  It works perfectly for system admins, but not for one of the users- it just sits there blank without redirecting.  I logged on as that user and was able to recreate the issue, which indicates this is something to do with permissioning. 

With some alert calls in the s-control, I was able to pinpoint that the javascript just stops when it tries to perform the SoQL query.  The user profile for this user has rights to the object being queried, has the API enabled and I tried adding a couple rights to the profile- View All Data and View Configuration, but to no end.  Is there a setting, in the profile or elsewhere, that would prevent a user from being able to run a SoQL query in an S-Control? 

I have similar s-controls in different salesforce instances and have never hit this before, very frustrating!
CaptainObviousCaptainObvious
Check the Field-Level Security of every field in your SoQL query. Most likely, that user's profile will have the specific field's "Visible" checkbox unchecked. If you want to "hide" a field from the user, mark it as "visible" in field security but don't add it to the page layout.
 
If that doesnt work, there may be other issues... Use Firefox with the Firebug plugin installed (it may have to be enabled in newer versions). Log in as the user and see if there are any errors- these show up at the bottom right hand corner of the browser window. Click the error to see a detailed description.
jgrenfelljgrenfell
The hazards of too many people with admin rights.  My query only queried on two fields and one of them wasn't marked as Visible, though there's no particular reason why.  That fixed it, thanks! 

I was trying to avoid the Firebug route just because the new version of Firefox doesn't support Firebug (I discovered after letting it upgrade) so it would have required downgrading Firefox first.
werewolfwerewolf
…or you could use Nightly Tester Tools, which often allows you to just mark addons like Firebug as compatible with the newer version.  Once in a while the addons break, but most of the time they just work.
jgrenfelljgrenfell
Very useful, thanks!
EmsEms
Jessie,
 
I'm trying to write an s-control that does something similar to what you describe, and could use an example... would you be willing to share your code?
 
Thanks,
Emily
jgrenfelljgrenfell
Certainly, here you go...
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <script type="text/javascript" src="/js/functions.js"></script>
    <script src="/soap/ajax/12.0/connection.js"></script>
    
<script type="text/javascript">
function initPage() {
 var newid = "{!$Request.newid}";
 var strSQL;
 var strRe;
 
 //Redirecting after matching child case to AP case
 if (newid.substring(0,3) == "a0V"){
  strSQL = "Select Id, Child_Case__c from Match_Child_Case__c where Id = '" +newid +"'";
 }
 
 //Redirecting after creating child/case
 if (newid.substring(0,3) == "003"){
  strSQL = "Select Id from Child_Case__c where Contact__c = '" +newid +"'";
 }
 
 
 if (strSQL != null){
  var result = sforce.connection.query(strSQL);
  var records = result.getArray("records");
  
  i=0;

  while ( i<records.length) {
   var rec = records[i];

   if (newid.substring(0,3) == "a0V"){
    strRe = rec.Child_Case__c;
   }
   
   if (newid.substring(0,3) == "003"){
    strRe =  rec.Id +"/e";
   }
   i++;
  }
 }

 if (strRe != null){
  window.parent.location.href = "/" +strRe;
 } else {
  //window.parent.location.href = "/" +newid;
 }
}
</script>

</head>

<body onLoad="javascript:initPage();">

</body>
</html>