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

Another SOQL Question


I have built a custom S-Control for the Home Tab, and it is working for the most part.  The problem is that I want to show a listing of Opportunities, with one of the columns being the Account that the Opportunity has.

This query runs fine in my S-Control:
Select Id, Name, Theme__c, Stagename, Sales__c, GP__c From Opportunity

This query runs fine in Apex Explorer 8.0, but it will not run inside my s-control:
Select Id, Name, Account.EPF_Account_ID__c, Theme__c, Stagename, Sales__c, GP__c From Opportunity

I read in a previous post that relational SOQL queries need to use the 8.0 API to get them to work in S-Controls.  If this is my problem, how can I use the 8.0 API in my s-control?


Are you using Javascript to run the SOQL query? If so, then you will need the following at the top of the S-Control:


I've used the 9.0 API in previous S-Controls without any problem. I'm sure 10 and 11 will work just fine as well.
I received an error when trying to add the REQUIRESCRIPT code that you suggested:
Error: Function REQUIRESCRIPT may not be used in this type of formula

However, I was able to change the following line from

Now, my query runs, but it breaks when I try to get the data out.

This code works:
SearchString="Select Id, Name, Theme__c, Account.EPF_Account_ID__c, Stagename, Sales__c, GP__c From Opportunity Where GP__c >= 0 ";
var queryResult = sforceClient.Query(SearchString);
for (var j = 0; j < NumberOfRecords ; j++) {
var Opportunity = queryResult.records[j];
TruncatedOpptyName = String(Opportunity.get("name")).substring(0,30)

However, when I add this line, it does not work:
TruncatedAccountName = String(Opportunity.get("Account.EPF_Account_ID__c")).substring(0,30)

Note.  Account.EPF_Account_ID__c is my relational part of the query.

Any ideas how I can get this to work?



Message Edited by Joanna on 11-02-2007 05:42 AM


Hi, Three comments:

1. It is far easier to learn how to "navigate" around the resultsets from Salesforce calls if you install a Firefox plug-in called Firebug.  This debugger lets you examine the variables that are returned so you can see their structure.

2. For example, you can't do the "Account.EPF..." dot notation inside a get() call.  You have to get the account object and then do another get on that result...   Opportunity.get("account").get("EPF...") sort of thing, if you have firebug, you can easily see that structure.

3. The "sforceClient.init" "style of s-control was from the Beta3 or earlier version of the Ajax toolkit.  So, somewhere in your code you have a "<script>" tag that looks something like:
<script src="" type="text/javascript">

This is obsolete and you should move to the latest version of the toolkit.  This is well documented on the AJAX section of the developer pages, as well as the things that changed between the Beta and the production version.  As it is now, you're mixing an obsolete toolkit with a more recent API version.  Not going to work in the long run.

Best, Steve.

I'm not sure, but that seems like it may be an older way of doing things. Here's what I would do:

I haven't tested it so it may give you some errors.

Message Edited by Jashugan on 11-02-2007 11:58 AM

Thanks so much!  The String(Opportunity.get("Account").get("EPF_Account_ID__c")).substring(0,30) syntax worked correctly.

Yes, it does look like this is an older way of coding.  This s-control is based on a demo Salesforce one that I have modified.  For production-level s-controls, I will make sure to use the more recent style of code.