Skip to content

Instantly share code, notes, and snippets.

@karanrajs
karanrajs / RecentRecordsController.cls
Created December 6, 2015 04:48
Apex class to get recently viewed records
public class RecentRecordsController {
@AuraEnabled public static List<sobject> getRecentRecords(String ObjectName,String limits,String fieldstoget){
List<Id> recentlyViewedIds = new List<Id>();
Integer limitofRecord = Integer.valueOf(String.escapeSingleQuotes(limits));
for(sObject obj : [Select Id from RecentlyViewed where Type =:String.escapeSingleQuotes(ObjectName)]){
recentlyViewedIds.add(obj.Id);
}
String queryString = 'Select '+ String.escapeSingleQuotes(fieldsToGet)+
@karanrajs
karanrajs / LDS.html
Last active September 1, 2015 18:30
<div class="slds-card">
<header class="slds-card__header">
<div class="slds-media slds-media--center">
<div class="slds-media__figure">
<div aura:id="svg_today">
<![CDATA[<svg aria-hidden="true" class="slds-icon slds-icon--small slds-icon-text-default">
<use xlink:href="/resource/SLDS080/assets/icons/action-sprite/svg/symbols.svg#priority"></use>
</svg>]]>
</div>
</div>
getFitbitData : function(component) {
var action = component.get("c.getUserDetails");
action.setCallback(this,function(response){
var state = response.getState();
if(state === 'SUCCESS'){
var parseJson = JSON.parse(response.getReturnValue());
component.set("v.User",parseJson.user);
}else if (state === "ERROR") {
console.log('Error');
}
@AuraEnabled public static string getUserDetails() {
HttpRequest req = new HttpRequest();
Http http = new Http();
req.setMethod('GET');
req.setEndpoint('callout:Fitbit/1/user/-/profile.json');
HttpResponse res = http.send(req);
return res.getBody();
}
@karanrajs
karanrajs / overallCoverage.html
Created February 26, 2015 18:01
Visualforce page to get the overall code coverage of org using Tooling API
<apex:page showHeader="true" sidebar="true" docType="html-5.0" standardStylesheets="false">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
//Tooling API query to get the overall code coverage
$.ajax('/services/data/v30.0/tooling/query/?q=SELECT PercentCovered FROM ApexOrgWideCoverage',
{
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer {!$Api.Session_ID}');
@karanrajs
karanrajs / VFRestAPI.html
Last active August 29, 2015 14:16
Sample to code call REST API from visualforce page
<apex:page>
<apex:includeScript value="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"/>
<script>
jQuery(document).ready(function($) {
// Pull 10 Contacts via the REST API
$.ajax('/services/data/v28.0/query?q=SELECT+Name+FROM+Contact+LIMIT+10',
{
beforeSend: function(xhr) {
// Set the OAuth header from the session ID
xhr.setRequestHeader('Authorization', 'Bearer {!$Api.Session_ID}');
// Check to see if person accounts are enabled.
public Boolean personAccountsEnabled()
{
// Describe the Account object to get a map of all fields
// then check to see if the map contains the field 'isPersonAccount'
return Schema.sObjectType.Account.fields.getMap().containsKey( 'isPersonAccount' );
}
@karanrajs
karanrajs / DuplicateCheck.cls
Created February 16, 2015 18:22
Trigger to call the Flow
trigger DuplicateCheck on Account (before insert,before update) {
for(Account acc: Trigger.New)
{
Map<String, Object> params = new Map<String, Object>();
params.put('varAccountName',acc.Name);
params.put('varAccountId',acc.Id);
Flow.Interview.DuplicateAccountCheck duplicateAccountCheck = new Flow.Interview.DuplicateAccountCheck(params);
duplicateAccountCheck.start();
@karanrajs
karanrajs / AssignmentrueinApex.cls
Created January 26, 2015 10:07
Enforce assignment rule in apex
// to turn ON the Assignment Rules in Apex
Database.DMLOptions dmlOptn = new Database.DMLOptions();
dmlOptn.assignmentRuleHeader.useDefaultRule = true;
leadObj.setOptions(dmlOptn);
@karanrajs
karanrajs / gauageChart.js
Last active August 29, 2015 14:06
Gauage chart using Amcharts
AmCharts.makeChart("chartdiv",
{
"type": "gauge",
"theme": "light",
"arrows": [
{
"id": "GaugeArrow-1"
},
{
"id": "GaugeArrow-2"