Skip to content

Instantly share code, notes, and snippets.

@dhruv-soft
dhruv-soft / salesforce-contact-sum-trigger-on-account
Created August 20, 2018 12:10
Count the total number of contacts at the account level in salesforce
/**
* Step 1:
* TriggerHandler
* This class is the primary class to centralize all Trigger logic
* This class is the virtual class, that you must extend for each of the class where you implement actual trigger logic
* public class ContactTriggerHandler extends TriggerHandler{
* }
* This class provides default and empty implementation for each of the trigger event, and processTrigger() method
which will call actual Trigger event methods that is developed in Handler class like ContactTriggerHandler
* Created by: contact (at) dhruvsoft.com
trigger ContactsOnAccount on Contact (after insert, after delete,after undelete,after update) {
Set<Id> aId = new Set<Id>();
if(Trigger.isInsert || Trigger.isUndelete){
for(Contact opp : Trigger.New){
aId.add(opp.AccountId);
}
List<Account> acc = [select id,No_of_Contacts_in_SFDC__c from Account where Id in:aId];
List<Contact> con = [select id from contact where AccountId in :aId];
IMAGE ( IF ( AND ( DeliveryDate__c >=56 , ISPICKVAL( Stage__c, "New Order" )),"/img/samples/color_green.gif",
IF ( ISPICKVAL( Stage__c, "New Order" ),"/img/samples/color_red.gif",
IF ( AND ( DeliveryDate__c >= 56 , ISPICKVAL( Stage__c, "In production" )),"/img/samples/color_green.gif",
IF ( AND ( DeliveryDate__c < 56 , DeliveryDate__c >= 42 , ISPICKVAL( Stage__c, "In production" )),"/img/samples/color_yellow.gif",
IF ( ISPICKVAL( Stage__c, "In production" ),"/img/samples/color_red.gif",
IF ( AND ( DeliveryDate__c >= 7 , DeliveryDate__c < 14 , FactoryShipmentDate__c > 35 , ISPICKVAL( Stage__c, "Transported" )),"/img/samples/color_green.gif",
IF ( AND ( DeliveryDate__c >= 14 , DeliveryDate__c < 21 , FactoryShipmentDate__c > 28 , ISPICKVAL( Stage__c, "Transported" )),"/img/samples/color_green.gif",
IF ( AND ( DeliveryDate__c >= 21 , DeliveryDate__c < 28 , FactoryShipmentDate__c > 21 , ISPICKVAL( Stage__c, "Transported" )),"/img/samples/color_green.gif",
IF ( AND ( DeliveryDate__c >= 28, DeliveryDate__c < 35 ,Fac