Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger CountContactsnew on Contact (after insert, after delete, after undelete) {
- List<id> accIdList = new List<id>();
- if(Trigger.isInsert || Trigger.isUndelete){
- For(Contact con1 : Trigger.new){
- accIdList.add(con1.accountid);
- }
- }
- if(Trigger.isDelete){
- For(Contact con1 : Trigger.old){
- accIdList.add(con1.accountid);
- }
- }
- List<Account> accUpdateList = new List<Account>();
- For(Account acc : [SELECT Contact_Recs__c,(SELECT id FROM Contacts) FROM Account WHERE id =: accIdList]){
- acc.Contact_Recs__c = acc.Contacts.size();
- accUpdateList.add(acc);
- }
- try{
- update accUpdateList;
- }Catch(Exception e){
- System.debug('Exception :'+e.getMessage());
- }
- }
- public class OpportunityCustomRollup {
- public static void CountRollup(List<Opportunity> lstOpportunity){
- set<id> oppIds = new set<id>();
- map<string, integer> classroomIDToDeskCountMap = new map<string, integer>();
- id objrecordtypeid = [SELECT Id FROM RecordType WHERE DeveloperName ='Fund_Raising'].Id;
- double amount = 0;
- try {
- for (Opportunity objOpportunity : lstOpportunity){
- oppIds.add(objOpportunity.Fund__c);
- }
- Fund__c objfund = [SELECT Id, Total_opportunity_amount__c FROM Fund__c WHERE Id = :oppIds];
- List<Opportunity> list_Opportunity = [SELECT Id, Amount FROM Opportunity WHERE Fund__c = :objfund.Id and StageName = 'Closed Won' and RecordTypeId =: objrecordtypeid];
- for(Opportunity AmountOpportunity : list_Opportunity) {
- amount += AmountOpportunity.amount;
- }
- objfund.Total_opportunity_amount__c = amount;
- update objfund;
- }
- catch (Exception e) {
- System.debug(e);
- }
- }
- }
- trigger newLeadTrigger on Opportunity (after insert , after update, after delete , after undelete) {
- if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate || trigger.isUndelete)){
- OpportunityCustomRollup.CountRollup(Trigger.new);
- }
- if(Trigger.isDelete)
- {
- OpportunityCustomRollup.CountRollup(Trigger.old);
- }
- }
Add Comment
Please, Sign In to add comment