0

I have a VF,which shows org wide limits,

<apex:page controller="SFLimitController" contentType="text/html" docType="html-5.0">
<apex:pageBlock title="Hello {!$User.FirstName}!" helpTitle="LIMITS"  HElpUrl="https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_limits.htm">
<b>Salesforce Limits</b>
</apex:pageBlock>
<apex:form >
<apex:pageBlock id="pg1">
<apex:panelGrid columns="4">
<apex:pageBlockSection id="pgs1">
<apex:pageBlockSectionItem >
<pre>{!Response}</pre><br/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:panelGrid>
 </apex:pageBlock>
 </apex:form>
</apex:page>

and the controller is:

public with sharing class SFLimitController{
public String Response { get; set;}

public SFLimitController()
{
Response=fetchData('GET');
}


public String fetchData(String GET)
{
Http h=new Http();
HttpRequest req=new HttpRequest();
req.setEndpoint('https://cs24.salesforce.com/services/data/v36.0/limits/ ');
 req.setHeader('Authorization','OAuth '+UserInfo.getSessionID());

req.setMethod('GET');
HttpResponse res=h.send(req);
        System.debug(res.getBody());
             return res.getBody();
}

}

As of Now,I am getting vf display in single line or as paragraph..how do i get the vf display in tabular format.Do guide me in the formatting process of vf.

3
  • if you make a callout to /services/data/v36.0/limits endpoint you will get list of records with there limit. You can just simply show those records in VF page
    – Ratan Paul
    May 25, 2016 at 8:50
  • 1
    Why use the REST API? If you're building a VisualForce page, you're already inside Salesforce and have an Apex controller. You can just use the Limits Apex class to find that information.
    – mkorman
    May 25, 2016 at 9:16
  • yeah good point by mkorman. You can use limit class as well
    – Ratan Paul
    May 25, 2016 at 9:20

2 Answers 2

1

Let me be elaborate about the limits in salesforce. There are two types of limit in Salesforce. 1.Transactional Limit : These limits exists over a particular transaction(when you press a butoon etc), like 100SOQL,150DML,100Callouts in transaction, 10 seconds transaction timeout. These limits gets reset every time a new transaction starts.

2.Org wide limits: These are orgwide limits and does get reset with often day change/or data change. eg 10000API limit /24hours, 100GB data storage etc.

In order to get tranactional limit you can directly use LIMIT class. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_limits.htm

for Org wide limits ,you can make a callout using the below code.

 Http http = new Http();
 HttpRequest request = new HttpRequest();
 request.setEndpoint('https://ap4.salesforce.com/services/data/v36.0/limits');
 request.setHeader('Authorization','OAuth '+UserInfo.getSessionID());

 request.setMethod('GET');
 HttpResponse response = http.send(request);
 system.debug(response.getBody());

Output will be:

{"ConcurrentAsyncGetReportInstances":{"Max":200,"Remaining":200},"ConcurrentSyncReportRuns":{"Max":20,"Remaining":20},"DailyApiRequests":{"Max":15000,"Remaining":14981},"DailyAsyncApexExecutions":{"Max":250000,"Remaining":250000},"DailyBulkApiRequests":{"Max":5000,"Remaining":5000},"DailyDurableGenericStreamingApiEvents":{"Max":10000,"Remaining":10000},"DailyGenericStreamingApiEvents":{"Max":10000,"Remaining":10000},"DailyStreamingApiEvents":{"Max":10000,"Remaining":10000},"DailyWorkflowEmails":{"Max":390,"Remaining":390},"DataStorageMB":{"Max":5,"Remaining":5},"DurableStreamingApiConcurrentClients":{"Max":20,"Remaining":20},"FileStorageMB":{"Max":20,"Remaining":20},"HourlyAsyncReportRuns":{"Max":1200,"Remaining":1200},"HourlyDashboardRefreshes":{"Max":200,"Remaining":200},"HourlyDashboardResults":{"Max":5000,"Remaining":5000},"HourlyDashboardStatuses":{"Max":999999999,"Remaining":999999999},"HourlySyncReportRuns":{"Max":500,"Remaining":500},"HourlyTimeBasedWorkflow":{"Max":50,"Remaining":50},"MassEmail":{"Max":10,"Remaining":10},"SingleEmail":{"Max":15,"Remaining":15},"StreamingApiConcurrentClients":{"Max":20,"Remaining":20}}

As you can see,whole org wide limit is displayed in JSOn, now you need to parse that JSON and display it on your VF page.

2
  • 1
    Thank you for the detailed explanation.. It was helpfull.
    – priya
    Jun 1, 2016 at 11:21
  • If my answer helped, you can upvote and mark it as solve, it will help others to reach solutions faster. Jun 2, 2016 at 6:02
2

I would suggest using a different approach: use the Limits Apex class. I don't see why you need the REST API for this if you're creating a VF page. The REST API is designed to allow external systems to communicate with your Salesforce, but a VF is inside salesforce. You're making your life more complicated if you want to use that API.

Broadly speaking, you would have to do this:

  • Create an Apex controller for your VF page. The controller should have properties representing all the limits you want to show.
  • Have your controller use the Limits class above to populate those properties
  • Create a VF page that shows the controller's properties using something like an outputText

That should give you all the building blocks you need to create such a page.

2
  • Thanks all for the reply, can you provide me a small example of how to go with it..
    – priya
    May 26, 2016 at 6:27
  • Why don't you edit your initial question, put your code there, and see how we can all help you? You just wrote the controller (you can give it a different name, as it does nothing with Rest). The values should be stored as properties (developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…) and then, for the Visualforce, here is a question similar to what you ask, with plenty of information: salesforce.stackexchange.com/questions/31752/…
    – mkorman
    May 27, 2016 at 7:47

You must log in to answer this question.

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