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
sgoremasgorema 

Scontrol to create a filtered list of opptys for an account?

Am I correct in thinking that I could build an scontrol with the Ajax toolkit that would allow me to display a subset of an Accounts opportunities and have it look like just another related list on the Account detail page? We would like to show a seperate list of just 'Open' opptys on the Account detail page. Can anyone point me in the direction of sample code that does something similar to this? thanks!
BritishBoyinDCBritishBoyinDC
Yes and no...

You can't replicate related lists using s-contols exactly - you can place an s-control that looks similar in a new section on the main area of the Accounts Page.

To get a sense of what it would look like, use Ajax Tools (check appexchange if you don't have it) which create the basic code to get the data and display it in basic HTML.

Create a new s-control, paste the code into it, create a new section on the Account Page, and you can then select the s-control from the available objects on the right (where the available fields are - just select s-controls from the drop down) and drag it into the new section.

If you think that it works ok functionally, you can then add css style sheets and HTML tags to make the section look pretty similar to an related list.


sgoremasgorema
thanks britishboy. i downloaded ajax tools into my developer account and i guess i am wondering whether there is an actual example of code that could do this or if i would have to piece together the various samples to get what i want. just dont want to reinvent something that is already written! thanks again for your reply.
BritishBoyinDCBritishBoyinDC
You can create a sample code using the explorer part of the Ajax Tools. But here's an example to get you started - create a new s-control and drop this code into it, and then add the s-control to a new section on the account page layout. As you'll see, the display format is very basic, as there is no style applied to it (or even a HTLM table format for that matter)

But once you get the idea of how the data is retrieve and displayed, putting it into a table and applying style formats is just using HTML.

Code:
<html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="/js/dojo/0.4.1/dojo.js"></script>

<script>
dojo.addOnLoad(init);

function init() {
var callback = {
onSuccess : displayResult,
onFailure : displayError
};
sforce.connection.query("SELECT Name, StageName, Amount, CloseDate FROM Opportunity WHERE AccountId = '{!Account.Id}' AND IsClosed = false", callback);
}

function displayResult(result) {
var it = new sforce.QueryResultIterator(result);
var html = [];
while(it.hasNext()) {
var record = it.next();
html.push("Name = " + record.Name + "<br>");
html.push("StageName = " + record.StageName + "<br>");
html.push("Amount = " + record.Amount + "<br>");
html.push("CloseDate = " + record.CloseDate + "<br>");
html.push("<hr>");
html.push("<br>");
}

document.getElementById("output-div").innerHTML = html.join("");
}

function displayError(error) {
document.getElementById("output-div").innerHTML =
"oops something went wrong ... " + error;
}
</script>


</head>
<body>

<div id="output-div"></div>

</body>
</html>

 



sgoremasgorema
thanks for your help on this. so i got access to the samples in the ajax toolkit and was able to at least get this to show up as a list. the only example out there creates a list that displays editable fields. i would not want them to be editable. any idea how i would code it if i did not want these fields to be editable and instead would want the oppty name to be a hyperlink and the rest to be simple displayed fields? here is the code..thanks again, stephanie
 
Code:
<html>
<head>

<style type="text/css">
.turbo-grid-classic { /* sets the main grid font size */
font-size: 12px;
}
.turbo-grid-classic-dta input, .turbo-grid-classic-dta textarea, .turbo-grid-classic-dta select {
font-size: 12px; /* grid input boxes and select menu font size */
}
.turbo-grid-classic-selected, .turbo-grid-classic-row-editing {
background-color: white; /* makes editing look like normal row-over */
}
</style>


<script src="/soap/ajax/10.0/connection.js"></script>
<script src="/js/dojo/0.4.1/dojo.js"></script>

<script>
dojo.addOnLoad(init);

function init() {
var callback = {
onSuccess : displayResult,
onFailure : displayError
};
sforce.connection.query("SELECT Id, Name, StageName, Amount, CloseDate FROM Opportunity WHERE AccountId = '{!Account.Id}' AND IsClosed = false", callback);
}

function displayResult(result) {


var sb = new sforce.StringBuffer();
sb.append("<table><tr><td>No</td><td>Name</td><td>Stage</td><td>Amount</td><td>Close Date</td></tr>");

while (true) {
if (result.size > 0) {
for (i = 0; i < result.records.length; i++) {
var oppty = result.records[i];
sb.append("<tr><td>").append(i).append("</td>");
sb.append("</td><td> ").append(editLink(oppty, "Name"));
sb.append("</td><td> ").append(editLink(oppty, "StageName"));
sb.append("</td><td> ").append(editLink(oppty, "Amount"));
sb.append("</td><td> ").append(editLink(oppty, "CloseDate"));
sb.append("</td></tr>");
}
}
if (result.done == "true") {
break;
} else {
result = sforce.connection.queryMore(result.queryLocator);
}
}
sb.append("</table>");
document.body.innerHTML = sb.toString();
}

function editLink(oppty, field) {
var value = oppty[field];
value = value — value : "Click to change";
return "<a href='javascript: editCell(\"" + oppty.Id +
"\",\"" + field + "\",\"" + value + "\")'>" +
value + "</a>";
}

function editCell(id, field, value) {
var newVal = prompt("Enter new text", value);
if (newVal === null || newVal === value) {
alert("Field not changed");
return;
} else {
value = newVal;
}
var opportunity = new sforce.SObject("Opportunity");
opportunity.Id = id;
opportunity[field] = value;

try {
result = sforce.connection.update([opportunity]);
if (result[0].getBoolean("success") == false) {
alert("update failed");
} else {
init();
}
} catch (e) {
alert("update failed");
sforce.debug.display(e);
}

}

function displayError(error) {
document.getElementById("output-div").innerHTML =
"oops something went wrong ... " + error;
}
</script>


</head>
<body>

<div id="output-div"></div>

</body>
</html>

 
BritishBoyinDCBritishBoyinDC
Something more simple might work...

Try this, and replace the accountcr fields with your oppty.[fieldname]

Code:
sb.append("<table class='detailList' cellpadding='0' cellspacing='0' border='0'>");
sb.append("<tr class='headerRow'>");
sb.append("<th class='' scope='col'>Account Name</th>");
sb.append("<th class='' scope='col' >Role</th>");
sb.append("</tr>");

while (true) {
if (result.size > 0) {
for (var i=0; i<records.length; i++) {
var accountcr = records[i];
sb.append("<tr class='dataRow even last first'>");

sb.append("<td class='dataCell'><a href=\"/");
sb.append(accountcr.Account.Id).append("\">");

sb.append(accountcr.Account.Name);
sb.append("</a></td><td class=\"dataCell\">").append(accountcr.Role);
sb.append("</td></tr>");
}
}
if (result.done == "true") {
break;
} else {
result = sforce.connection.queryMore(result.queryLocator);
}
}
sb.append("</table>"); 

 

sgoremasgorema

thanks..this looks much better. the only issue i am now having is the hyperlink links to the opportunity but it does not use the whole browser to go there. it navigates to it just from the layout section.

I also found this code which replicates the look and feel of the related list. Just have no idea how I would add the code to populate it with records!

http://wiki.apexdevnet.com/index.php/Salesforce_Look_and_Feel.html

BritishBoyinDCBritishBoyinDC
You probably need to change the link to replace the parent window - I have some code to do that - I'll dig it oout for you.

Re the example, it should just be a question of wrapping their code around your HTML, since it is really a wrapper to the HTML table...