Skip to content

Instantly share code, notes, and snippets.

trigger efficientSOQL on Invoice_Statement__c(before insert,before update)
{
//perform SOQL query outside the for loop
//This query runs once for all item in the Trigger.New
for(Invoice_statement__c inv : [Select Id,Description__c,(select Id,Units_Sold__c from Line_Item__r) From Invoice_Statement__c where Id IN : Trigger.newMap.KeySet()])
{
for(Line_Item__c li:inv.LineItem__r)
{
//do any operation
}
@karanrajs
karanrajs / QuickCasecomment.cls
Last active July 25, 2017 01:39
Adding Case Comment from Salesforce1
global class QuickCasecomment
{
public QuickCasecomment(ApexPages.StandardController controller) {
}
@RemoteAction
public static boolean CreateComment(Id CaseId,String comment,string publish){
CaseComment newCom = new CaseComment();
@karanrajs
karanrajs / VFRemoteObject.html
Last active September 27, 2017 09:07
A Visualforce page to demonstrate the functionality of Visualforce Remote Objects
<!---
@author : Karanraj
@Description : A Visualforce page to demonstrate the functionality of Remote Objects
-->
<apex:page showHeader="false" standardStylesheets="false">
<!-- Boostrap and jQuery file -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" />
@karanrajs
karanrajs / userGroupRemoval.cls
Last active August 29, 2015 14:05
Batch class to remove user from group, if the user is assigned to multiple group
global class userGroupRemoval implements Database.Batchable<sObject> {
String query = 'Select Id from user where isActive = true';
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope) {
List<user> userRecord = (List<user>)scope;
List<GroupMember> duplicateGroupId = new List<GroupMember>();
Set<Id> userId = new Set<Id>();
for(GroupMember gpm : [Select Id,userorGroupId from GroupMember where userorGroupId IN:userRecord]){
@karanrajs
karanrajs / LinkedInRegHandler.cls
Created September 5, 2014 12:19
Authentication Registration Handler class for the LinkedIn
global class LinkedInRegHandler implements Auth.RegistrationHandler{
//This method is called when the user log-in using social single sign-on credentials.
//This method will return the user details, either you can create new user
//or return the existing user if the match is found
global User createUser(Id portalId, Auth.UserData data){
if(data.email.contains('@gmail.com')){
User u = [Select id,email,isActive from user where email =: data.email and isActive = true Limit 1];
return u;
}
@karanrajs
karanrajs / ToolingAPI.html
Last active August 29, 2015 14:06
Getting over all code coverage 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(){
$.ajax('/services/data/v30.0/tooling/query/?q=SELECT PercentCovered FROM ApexOrgWideCoverage',
{
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer {!$Api.Session_ID}');
},
@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"
@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 / 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();
// 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' );
}