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
Dhana t 1Dhana t 1 

how to get records in vf page without using controllers?

how to get records in vf page without using controllers(Either standard or custom) or class methods like properties...

can anyone help me out of this?

Thanks
KRayKRay
I'm not sure if this is possible. If so, I may be more trouble doing it this way vs creating a controller. 
Rahul BorgaonkarRahul Borgaonkar
Hi,

I found a code which is written in old project. This may be useful.
 
<apex:page showHeader="false" showChat="false" sidebar="false" >
    <script type="text/javascript">
        var __sfdcSessionId = '{!GETSESSIONID()}';
    </script>
    <script src="../../soap/ajax/27.0/connection.js" type="text/javascript"></script>
    <script type="text/javascript"> 
    
    var state;    
    window.onload = setupPage;
    function setupPage() 
    {
      //function contains all code to execute after page is rendered

      state = { //state that you need when the callback is called
          output : document.getElementById("output"),
          startTime : new Date().getTime()};
        
        var callback1 = {
          onSuccess: showTotalLicensesThisMonth,

          onFailure: queryFailed,
          source: state};
          
        sforce.connection.query(
          "SELECT sum(Total_Seats__c) totallicensethismonth FROM Opportunity where Platform__c = 'UK' and (not name like '%Trial%') and Order_Processed__c = True and Next_Steps__c in ('Customer - Provisioned', 'Customer - Provisioned – Awaiting Training') and CloseDate = THIS_MONTH and StageName not in ('Closed Lost','Closed Cancelled') and accountid not in (select id from account where name like '%zzz%') and id not in (SELECT OpportunityId FROM OpportunityLineItem where PricebookEntry.name = 'CloudCall_Intl_DDI_Yearly')",
           callback1);
       
    }

    function queryFailed(error, source) 
    {
        //alert("An error has occurred: " + error);
        console.log("An error has occurred: " + error);

    }

    function showTotalLicensesThisMonth(queryResult, source) 
    {
        //alert(queryResult);
        if (queryResult.size > 0) 
        {
            //get the records array
            var records = queryResult.getArray('records');
            
            var totallicensethismonth = isNaN(parseFloat(records[0].totallicensethismonth)) ? 0 : parseFloat(records[0].totallicensethismonth);
            document.getElementById('totallicensethismonth').innerHTML = formatNumber(totallicensethismonth,2);
        }
    }

  </script>
    <table cellpadding="3" width="100%" >

    <tr>
    <td style="font-size:12px;font-weight:bold;" width="70%">
        Licenses Provisioned this month: 
    </td>
    <td style="font-size:12px;font-weight:bold;text-align:right" width="30%">
        <a href="/00OG0000004eh5f" title="click to see report" target="_blank"><span id="totallicensethismonth" style="font-size:12px;color:#F00"></span></a>
    </td>
    </tr>

    </table>
</apex:page>
You can extract data using  sforce.connection.query() function.

Regards,

Rahul
 
Cory CowgillCory Cowgill
I would highly recommend you use an Apex Controller / Extension to do the work. That way you can use data binding, javascript remoting, etc. Also if you use the connection.js example you will consume API calls unecessarily.  If you have a high volume org this will not scale and you are wasting API calls for example.

connection.js has largely been deprecated in favor of Javascript Remoting and other features which better solve the issues presented and don't consume those critical limits..
Abhi_TripathiAbhi_Tripathi
Hi Dhana, you can use Visualforce remote object, salesforce have this awesome thing in that you can query the records and can perform DML operations as well without having controller.

For a brief examples of it you can go for this post.
http://abhithetechknight.blogspot.in/2015/02/visualforce-remote-objects-query.html

Let me know for further issues
 
Dhana t 1Dhana t 1
thank you all....
got Idea...