Skip to content

Instantly share code, notes, and snippets.

@snugsfbay
Forked from az-ak/OrgLimits (Visualforce page)
Created February 10, 2020 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snugsfbay/ddee8ee1b73b54e1dea5b8c00743c7b0 to your computer and use it in GitHub Desktop.
Save snugsfbay/ddee8ee1b73b54e1dea5b8c00743c7b0 to your computer and use it in GitHub Desktop.

OrgLimits (Visualforce page)

Installation and usage

Create new Visualforce page and paste all the contents. After creating a tab for the Visualforce page, you can see Org usage metrics provided by /v38.0/limits/ REST Api resource.

Also you can install this as an unmanaged package from here.

To add this page your Salesforce1 mobile app:
[setup]->[Mobile Administration]->[Salesforce1 Navigation]

Japanese explanation

Salesforce REST Apiの /v38.0/limits/ をアクセスし、組織の制限を確認するVisualforceページです。 新規Visualforceページを作成しコードをコピーしたうえで、Visualforceタブを作成すれば使用できます。
このリンクより非管理パッケージとしてもインストール可能です。

Salesforce1モバイルアプリで見たい場合には
[設定]→[モバイル管理]→[Salesforce1ナビゲーション]
でページを追加して下さい。

Note

  • No Apex code used.
  • Using hosted Bootstrap and JQuery library.
  • If higher API version supports additional metrics, recommend you to update version number in following line:
      $.ajax('/services/data/v38.0/limits',
<apex:page docType="html-5.0" sidebar="false">
<apex:stylesheet value="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"/>
<script>
jQuery(document).ready(function($) {
$.ajax('/services/data/v38.0/limits',
{
beforeSend: function(xhr) {
// Set the OAuth header from the session ID
xhr.setRequestHeader('Authorization', 'Bearer {!$Api.Session_ID}');
},
success: function(json) {
var tbody = $('#tableData');
for(key in json) {
// alert(key + ":" + json[key].Remaining + ":" + json[key].Max);
var usage = json[key].Max-json[key].Remaining;
var ratio = (json[key].Max-json[key].Remaining)/json[key].Max*100;
if (ratio < 80) {
var color = "progress-bar-success";
} else if (ratio < 90) {
var color = "progress-bar-warning";
} else {
var color = "progress-bar-danger";
}
var td = $('<tr>')
.append('<td>' + key + '</td>')
.append('<td class="text-right">' + usage + '</td>')
.append('<td class="text-right">' + json[key].Max + '</td>')
.append('<td><div class="progress"><div class="progress-bar ' + color + '" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="' + ratio + '" style="width:' + ratio + '%"></div></div></td></tr>')
tbody.append(td);
}
},
error: function(jqXHR, textStatus, errorThrown) {
// Oops - what went wrong?
alert(jqXHR.status + ': ' + errorThrown);
}
}
);
});
</script>
<h1>Org Limits</h1>
<table class="table table-condensed">
<thead>
<tr><th class="col-sm-6"></th><th class="text-right col-sm-2">Usage</th><th class="text-right col-sm-2">Max</th><th class="text-center col-sm-2">Percentage</th></tr>
</thead>
<tbody id="tableData">
</tbody>
</table>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment