Posts

Showing posts from 2014

Manage Order of Trigger Execution in Salesforce for Object

Hi guys, Note: Handle the trigger order of execution: If any Case when you required to write 4 triggers on different - different events but on same object then don't write 4 trigger for same. Suppose you have 4 trigger on Account Object. 1- AccTrigger1.trigger 2- AccTrigger2.trigger 3- AccTrigger3.trigger 4- AccTrigger4.trigger Solution is mention as below STEP 1- Create only one trigger for one object(Account) like- In above case instead of having 5 triggers on  STEP 2- Create only 1 trigger that is AccountTrigger.trigger on Account Object. // Create Trigger as Mention Below trigger AccountTrigger on Account (after insert, after update, before delete, before insert, before update)  {     AccortunityTriggerHandler triggerHandler = new AccortunityTriggerHandler(Trigger.isExecuting,Trigger.size);         if(Trigger.isBefore && Trigger.isInsert){         triggerHandler.OnBeforeInsert(trigger.new, trigger.NewMap);     }         if(Trigger.isAft

How to Increment Sr No on Visual force Page

<apex:page>     <apex:form >             <table style="width:auto;margin-top:10px;" border="1" cellspacing="0" cellpadding="0" >                 <tr>                     <td  style="background-color:lightblue;font-weight:bold;vertical-align:bottom;text-align:center;width:34px;"> Sr.No </td> <td  style="background-color:lightblue;font-weight:bold;vertical-align:bottom;text-align:center;width:34px;"> Name</td>                 </tr>             </table>                 <apex:variable value="{!0}" var="Count"/>                              <table id="tblInfo" style="width:auto;border-top: 0;" border="1"  cellspacing="0" cellpadding="0" >                     <tbody>                            <apex:repeat value="{!lstWrapper}" var="wrap">   

Batch Class and Dynamic Create Email Template

global  class batchClasAndSendDynamicEmailTemplate implements Database.Batchable<Sobject> {     set<Id> suid= new set<Id>();     set<id> sweekplanid = new set<id>();     map<id,user> mapManager = new map<id,user>();     Map<ID,List<Weekly_Plan__c>> mapUserIdToAWPList = new Map<Id,List<Weekly_Plan__c>>();     Map<ID,String> mapUserIdToManagerEmail = new Map<Id,String>();      Map<ID,String> mapManagerIdTomanager = new Map<Id,String>();      list<string> lstEmail = new list<string>();     string tempBody = '';     List<Weekly_Plan__c> listPJPWeeklyUpdate = new List<Weekly_Plan__c>();          global Database.Querylocator start(Database.Batchablecontext BC)     {         return Database.getQueryLocator([Select Is_Rejected__c,                                                 No_of_Day_Plan__c,                                                  Status__c, 

Dynamic SOQL Query

String qString = 'Select Id , Name , FirstName , LastName , Account.Name , Kips_Designation__c , Kips_Relationship__c , Birthdate , Kips_Date_of_Anniversary__c , Kips_Feast_Date__c , Kips_Annual_Gift__c From Contact ';                  qString+= ' where Account.Name like \'%' + AccountName+ '%\'';                             if(objGift.kips_Type__c !=null && objGift.kips_Type__c !='')         {             if(objGift.kips_Type__c == 'School')             {                 //qString+= ' and Account.RecordType.Name like \'%' + objGift.kips_Type__c+ '%\'';                      qString+= ' and Account.RecordType.Name  =  \'' + objGift.kips_Type__c+ '\'';                 qString+= ' and Kips_CURRENT_SCHOOL_Active__c = \'Yes\'';                         qString+=' and Kips_Key_Person__c = true';              }             if(objGift.kips_Type__c == 

On Custom Button VF page Open in new Tab

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} var accId="{!Account.Id}"; window.open("/apex/vfpageName?id="+ accId ,"mywindow");

Show Loading Image on Change Event using Action Status

<div dir="ltr" style="text-align: left;" trbidi="on"> <span style="background-color: #d2eaf1; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold;">High Value Payments</span><b><style> .Processing         {             position: fixed;             background: url('/img/loading32.gif');             background-repeat: no-repeat;             background-position: center;                         width: 100%;             height: 100%;             z-index: 1004;             left: 0%;             top: 0%;         } </style> <apex:form> <apex:actionstatus id="statusProcessing" startstyleclass="Processing"> <apex:commandbutton action="{!onClickSave}" oncomplete="scroll(0, 2);" rerender="idoutPanlMsg" status="statusProcessing" value="Save"> </apex:commandbutto

How to Calculate Sum of Amount and Pass Date Value in Url

if( Apexpages.currentPage().getParameters().get('date') != null && Apexpages.currentPage().getParameters().get('date') != '' ) { string strDate= Apexpages.currentPage().getParameters().get('date'); string[] arrDate = strDate.split('-'); if( arrDate.size() > 2 ) objProject.start_Date__c=date.newInstance( integer.valueof( arrDate[0] ), integer.valueof( arrDate[1] ), integer.valueof( arrDate[2] ) ); } Calculate some of Amount  // Declare Variable {!TEXT(ROUND(Total_due,0))} Total {!TEXT(ROUND(GrandTotal,0))}

Update Record on Custom Button Using JavaScript on Detail Page

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}  var DayPlanRecord = new sforce.SObject("Object Name");  DayPlanRecord.id = "{!ObjectName.Id}";  DayPlanRecord.FieldName = false ;  var recordType = sforce.connection.query("Select ID,FieldName, Name From ObjectName where FieldName = false " );  DayPlanRecord.FieldName = true ; result = sforce.connection.update([DayPlanRecord]);  window.location.reload();

Roll Up Contact Count on Account

trigger rollupCount on Child__c (after insert, after delete)  {  List masterList = new List(); Map masterMap = new Map(); for(List mstrList : [Select id, Trigger_Rollup_Count__c from Master__c]) {  for(Master__c master : mstrList) { masterMap.put(master.Id, master);  } } if(trigger.isInsert) { for(Child__c child : trigger.new) {    if(masterMap.containskey(child.Master__c)){ if(masterMap.get(child.Master__c).Trigger_Rollup_Count__c != null){ Master__c mas = masterMap.get(child.Master__c); mas.Trigger_Rollup_Count__c = mas.Trigger_Rollup_Count__c + 1;    masterList.add(mas);    } else{ Master__c mas = masterMap.get(child.Master__c); mas.Trigger_Rollup_Count__c = 1; masterList.add(mas);  }  }  }  }  if(trigger.isDelete) { for(Child__c child : trigger.Old) {  if(masterMap.containskey(child.Master__c)) {  Master__c mas = masterMap.get(child.Master__

Get Day of Today

date intNoofDays ;   intNoofDays = system.today();  Output: intNoofDays__ 2014-09-25 00:00:00   system.debug('intNoofDays__'+intNoofDays);   Datetime dt = DateTime.newInstance(intNoofDays,  Time.newInstance(0, 0, 0, 0));   Output: dt___2014-09-24 18:30:00   system.debug('dt___'+dt);   String strTodayDayName = dt.format('EEEE');   System.debug('Day : ' + strTodayDayName);   Output: Day : Thursday

Based on Profile Select Sobjects............

Cls:  SobjectListcls public class SobjectListcls {      set<string> salesforceObjectSet = new set<string>();     Map<Id,List<ObjectPermissions>> permissionsetIdAndlstObjectPermissions = new Map<Id,List<ObjectPermissions>>();       public string strSobjectName{get;set;}     public SobjectListcls()     {       onlyReadPerrmission();       system.debug('sobject...'+salesforceObjectSet);     }     public void onlyReadPerrmission()     {         String userid = UserInfo.getUserId();         User thisUser = [select id, profile.Name from User where id=:userid];          system.debug('UserName...'+thisUser);         permissionset perset = [select id from permissionset where PermissionSet.Profile.id =:thisUser.profileId];         system.debug('check ---------perset'+perset);             PermissionSetAssignment[] lstPermissionSetAssignment =[SELECT AssigneeId,PermissionSetId FROM PermissionSetAssignment where Assi

onContactAddTotalNumOfConAtAccLabel: When Contact is inserted or deleted then count the contact at Account Level

trigger onContactAddTotalNumOfConAtAccLabel on Contact (after delete, after insert) {         List<Account> lstacc=new List<Account>();     set<ID> accid= new Set<Id>();     list<Account> lstAccountToUpdate = new list<Account>();     if(trigger.isInsert && trigger.IsAfter)  {                   for(Contact con:trigger.new)               {                 accid.add(con.AccountID);               }              lstacc= [Select ID, TotalContact__c from Account where ID In: accid];          if(lstacc.size()>0)      {                               for(Account accObj:lstacc)                   {                              for(Contact conObj:trigger.new)                              {                                  if(accObj.ID==conObj.AccountID)                                  {                                         Integer i=0;                                             if(accObj.TotalContact__C!=null)