1

I am tasked with creating an inline view from the accounts view page that shows opportunity amounts (won-closed) for the 12 months of the year, a total amount field, and prior year amounts, associated to a particular account.

I am on the professional edition, so I understand I cannot make custom classes/controllers.

I found this snippet of code online, but was wondering if there was any equivalent with a standard controller that I could use, and any modification/addition to the code to more tailor it to my requirements?

VF page :
<apex:page controller="CalculationOnVFCnt" id="thePage">
    <apex:form id="theForm">
        <apex:pageblock id="theBlock">
            <apex:pageBlockTable value="{!Opportunities}" var="oppty" id="theBlockTable" >
                <apex:column headerValue="Name">
                    <apex:outputField value="{!oppty.Name}"/>
                </apex:column>
                <apex:column headerValue="Amount">
                    <apex:outputField value="{!oppty.Amount}"/>
                </apex:column>
                <apex:column headerValue="Total Amount">
                    <apex:outputText id="amountM"/>  
                    <script>
                        var amount = '{!oppty.Amount}';
                        var d = new Date();
                        var n = d.getMonth()+1;
                        var total = amount*n;
                        var elementId = document.getElementById('{!$Component.amountM}')
                        elementId.innerHTML= total;
                    </script>
                </apex:column>
            </apex:pageblockTable>
        </apex:pageblock>
    </apex:form>
</apex:page>

And the controller:
public Class CalculationOnVFCnt {
    public List<Opportunity> getOpportunities() {
        return [select Id,name,amount from opportunity ];
    }
}

I have it envisioned as looking something like:

    | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec ||Total| 
2014| 199 |  0  | 50  | etc | etc | etc | etc | etc | etc | etc | etc | etc ||xxxxx|
2013| 100 | 25  | 35  | etc | etc | etc | etc | etc | etc | etc | etc | etc ||xxxxx|
2012|  25 | 400 | 72  | etc | etc | etc | etc | etc | etc | etc | etc | etc ||xxxxx|

I'm not a coder, so any help would be much appreciated.

2 Answers 2

1

It cannot be done with a standard controller because you must total all the amounts across Opportunities for an Account, and that totaling must happen in a custom controller.

If you can do it with JavaScript, then go for it, but I think that with Professional Edition it won't work.

Plus, your standard controller would have to be the Account standard controller - and while you can display all the Opportunities for that Account in a VF page, segmenting them by closed/won or by month is not possible in a standard controller.

3
  • Thanks for the information David, appreciate it. What I find strange about salesforce restrictions is they're a bit arbitrary and unclear where some stop and others start. for example an app 'gridbuddy' allows these types of information break downs you're talking about, totalling opportunities for an account, breaking it down via stage, but I can't really picture it doing precisely what I need, but I may have to look more towards that if it offers 'most' of what I'm looking for. I'm just no coder, which makes it tough.
    – Ryan T
    Commented Apr 16, 2014 at 20:41
  • GridBuddy is in a managed package, so it is allowed to use custom controllers. It's not arbitrary at all - you are not allowed to write custom Apex code in Professional Edition, but you can install any AppExchange package that has been created to work with Professional Edition. Commented Apr 16, 2014 at 20:42
  • The reason I find it arbitrary is, you can have someone develop an app for you with custom controllers (the apps are free in some cases!) and fully use them on professional edition, therefore gaining access to custom API.
    – Ryan T
    Commented May 26, 2014 at 15:10
0

Here's one way to do it: When you load the page it will have to have an account ID in the URL It will grab it if it sits on the Account page as an embedded VF page on the page layout OR you can populate the ID in the URL like so:

 https://Salesforce_instance/apex/PAGENAMEHERE?id=001D000000IRt53






    <apex:page standardController="Account">
    <apex:includeScript value="/soap/ajax/29.0/connection.js"/>
    <apex:includeScript value="/soap/ajax/29.0/apex.js"/>
     <head>
    <script>
        sforce.connection.sessionId = "{!$Api.Session_ID}";
    function test(){
    var tableN = "";
    var __sfdcSessionId = '{!GETSESSIONID()}';
    var AId ="{!Account.Id}";
    console.log(AId);
    var queryResults = new Array();
   queryResults = sforce.connection.query('Select Name,Id,Amount from Opportunity where AccountId =\''+AId+'\' ');
     var keys = Object.keys(queryResults.records);
    console.log(keys);
     tableN+="<tr>"
                                            for (var y = 0; y < keys.length; y++) {
                                            var val = queryResults.records[keys[y]];
                                            tableN+="<tr>";
                                            tableN+="<td>"+val.Id+"</td>";
                                            tableN+="<td>"+val.Amount+"</td>";
                                            tableN+="<td>"+val.Name+"</td>";
                                            tableN+="</tr>";
                                            console.log(val);
                                            }
    tableN+="</tr>";
     document.getElementById("table").innerHTML+=tableN;
    }
    </script>

    </head>

    <body>
    <button onclick="test();">test </button>
        <table border="1" id="table"></table>
    </body>
    </apex:page>

NOTE: STYLE AND EDIT THE QUERY HOW EVER YOU WOULD LIKE! This works, I've tested it.

7
  • 1
    The asker specifically said that he is in Professional Edition - so he cannot make a custom controller or extension. Commented Apr 16, 2014 at 17:50
  • Hi, thanks for your help alphabravo - I will be putting a VF page directly on the account page (so it can pick up the information that way, right?) I tried testing the code you've provided (without the first url line -- unless i misunderstod that part) and get a button that says 'test' which nothing happens when clicking it. Was I to change anything specifically to see anything other than that? Or have you changed the information yet to be useable without a custom controller? i see the first line mentions using the standardcontroller 'account' is there anything else needed in the VF page?
    – Ryan T
    Commented Apr 16, 2014 at 20:32
  • Hi Ryan, I changed it so it can sit on an account page and pull the information. You need to have the standard controller as the account. If you are still getting an error your best bet is to look at the Javascript console. Chrome - CTRL+SHIFT+J FireFox - CTRL+SHIFT+K. Let me know if it has any crazy errors.
    – AlphaBravo
    Commented Apr 16, 2014 at 21:29
  • If it doesn't work. Then you might need to get an add-on for your profession edition allowing API.
    – AlphaBravo
    Commented Apr 16, 2014 at 21:35
  • I enabled javascript console, nothing showed until i clicked 'test' then got: Refused to set unsafe header "User-Agent" connection.js:593 POST c.na15.visual.force.com/services/Soap/u/29.0 500 (Server Error) connection.js:594 Uncaught {faultcode:'sf:API_DISABLED_FOR_ORG', faultstring:'API_DISABLED_FOR_ORG: API is not enabled for this Organization or Partner', and by add-on you mean something that costs extra I would presume.. guess I'm out of luck. appreciate the efforts though.
    – Ryan T
    Commented Apr 17, 2014 at 18:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .