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
wkuehlerwkuehler 

S-Control to display my accounts

I would like to create a tab that would display the equivalent of an account report with Account Name, Account Site, and Account Phone as the columns. It should display all accounts owned by the logged in user.

Is an S-control the best approach here? If so, any info to get me started would be appreciated.

Thanks

Wkuehler
jf317820jf317820
Why not just create a view in the account tab with those columns and the criteria being "My Accounts"?
wkuehlerwkuehler
What I am trying to do is determine how to query objects, determine how to display those objects, and eventually design a tab that would display the following:

AccountName    AccountSite    BillingAddress    ShippingAddress
       ContactName    MobilePhone    HomePhone    EmailAddress
       ContactName    MobilePhone    HomePhone    EmailAddress
       ContactName    MobilePhone    HomePhone    EmailAddress
AccountName    AccountSite    BillingAddress    ShippingAddress
AccountName    AccountSite    BillingAddress    ShippingAddress
       ContactName    MobilePhone    HomePhone    EmailAddress
AccountName    AccountSite    BillingAddress    ShippingAddress
       ContactName    MobilePhone    HomePhone    EmailAddress
       ContactName    MobilePhone    HomePhone    EmailAddress

In sudocode....

Select AccountName, AccountSite, BillingAddress, ShippingAddress from Account where OwnerID equals CurrentLoggedInUser

For each AccountSelected
    Display AccountName, AccountSite, BillingAddress, ShippingAddress
    If AccountHasContacts, for each Contact
        Display ContactName, MobilePhone, HomePhone, EmailAddress

I am not aware of a way in Salesforce to display the information in this format.  An Account Contact report comes to mind, however, that would display all the account information for each contact.  Also, if an account did not have a contact, it would not be displayed either.

Thanks for your help

Message Edited by wkuehler on 05-11-2006 10:34 AM

SteveBowerSteveBower
It sounds like you just need a framework to get started.  Someone asked for something in the Best Practices discussion list about creating a report for displaying the ContactRoles and since I had something handy, I posted this reply.  I suspect that the S-Control for this might give you a leg up on what you need.  It assumes you're "starting" from a contact instead of an account, and it's querying ContactRoles instead of contacts.  But perhaps it will give you some ideas.

If not, feel free to write me and we can talk.  What you want is pretty straightforward.

(below is pasted from the other discussion...)
--------------------------------------------------------------------------------------------------------------

Here is a link to the AppExchange package. 

http://www.salesforce.com/appexchange/detail_overview.jsp?id=a0330000001mvUBAAY

It contains a Custom Link which is intended to be placed on the Contact Page Layout, and an S-Control which, when fired, will display a table with information about all the Account Contact Roles that this current Contact is linked with.  I've only displayed the isPrimary, and the Account Name.

Hope this helps, Steve Bower.

wkuehlerwkuehler
That was the start I needed.  Here is the code that queries accounts, then for each account queries its contacts.  I will be using this as a base for several projects.

Thanks again for your help.


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<script type="text/javascript" src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js"></script>

<script language="javascript">
<!--
function init()
{
    sforceClient.useCookies = true;
    sforceClient.registerInitCallback(doit);

    // Use this for Sandbox testing.
    //sforceClient.setLoginUrl("https://test.salesforce.com/services/Soap/u/7.0");

    var ir = sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", true);
}

function getBack(Id)
{
    // This brings me back to the Objects overview page.
    var r = "{!Scontrol_URL}".split(/salesforce.com/);
    var whichId = "{!User_ID}"; // set default.
    if (Id != null) whichId = Id;
    return r[0] + "salesforce.com/"+whichId;
}

function goBack(Id)
{
    window.parent.parent.location.href = getBack(Id);
}

function getEdit(Id)
{
    return getBack(Id)+"/e";
}

function goEdit(Id)
{
    window.parent.parent.location.href = getEdit(Id);
}

function err(m)
{
    alert(m);
    goBack();
}

function newTR()
{
    var tr = document.createElement("TR");
    tr.class = "dataRow even first";
    return tr;
}

function newTD(text)
{
    var td = document.createElement("TD");
    td.class = "dataCell";
    if (text != "" && text != null)
    {
        var txt = document.createTextNode(text);
        td.appendChild(txt);
    }
    return td;
}

function doit()
{
    //alert("sforceClient.getLoginUrl() = " + sforceClient.getLoginUrl()); // To Set breakpoints.

    // For this contact, we will select all the Contact_roles, and their associated
    // Account information and display them with active links to the Accounts and Contacts.

    var UserId = "{!User_ID}";
    var q = "select Id, Name, Site from Account where OwnerId = '" + UserId + "'";
    var aq = sforceClient.Query(q);
    
    if (Sforce.Util.dltypeof(aq) != "QueryResult" )
    {
        err("Error querying accounts = " + aq);
    }
    else
    {
        var e = document.getElementById("TBody");
        tb = document.createElement("TBODY");
        tb.id = "TBody";
        if (aq.records.length <= 0 )
        {
            alert("This user has no accounts.\n");
            goBack();
        }
        else
        {
            for (var j=0; j < aq.records.length ; j++)
            {                
                var tr = newTR();
                var td = newTD();
                                
                var a = document.createElement("A");
                a.href = getBack(aq.records[j].get("ID"));
                var t = document.createTextNode(aq.records[j].get("Name") + "  -  " + aq.records[j].get("Site"));
                a.appendChild(t);
                td.appendChild(a);
                tr.appendChild(td);
                
                /*var td = newTD(aq.records[j].get("Site"));
                tr.appendChild(td);*/
                
                tb.appendChild(tr);

                
                //Display all contacts for the current account
                var q = "select Id, FirstName, LastName from Contact where AccountID = '" + aq.records[j].get("ID") + "'";
                var cq = sforceClient.Query(q);
                if(cq.records.length <= 0)
                {
                    var nocontacts = "No contacts, do nothing";
                }
                else
                {
                    for (var k=0; k < cq.records.length ; k++)
                    {   
                        var tr = newTR();
                        var td = newTD();
                        
                        var td = newTD(cq.records[k].get("FirstName") + cq.records[k].get("LastName"));
                        tr.appendChild(td);
                        
                        tb.appendChild(tr);
                    }
                }
            }

            e.parentNode.replaceChild(tb,e); // I'm the node passed in, replace myself.
        }
    }
}

//-->
</script>
</head>
<body class="account editPage" style="POSITION: absolute" onLoad="init();">
<!-- Style Sheets supplied by Salesforce.com
<link href="https://na1.salesforce.com/dCSS/Theme2/default/common.css"
type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet">
<link href="https://na1.salesforce.com/dCSS/Theme2/default/custom.css"
type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet"> --!>
<style type="text/css">
<div class="bPageBlock bEditBlock secondaryPalette">
<div class="pbHeader">
<div class="pbSubheader first tertiaryPalette" id="LookupResults">
<h3> All Accounts for: {!User_FullName} </h3>
</div>
</div>

<div class="pbBody">
<table class="list" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr class="headerRow">
<th scope="col" class="">Account Name</th>
<th scope="col" class="">Account Site</th>
<th scope="col" class="">Temp2</th>
<th scope="col" class="">Temp3</th>
</tr>
</tbody>
<tbody id="TBody">
<!-- replace this node. -->
</tbody>
</table>
</div>

</div>
</body>
</html>