Guest User

Untitled

a guest
Jan 22nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. trigger CountContactsnew on Contact (after insert, after delete, after undelete) {
  2.  
  3. List<id> accIdList = new List<id>();
  4. if(Trigger.isInsert || Trigger.isUndelete){
  5. For(Contact con1 : Trigger.new){
  6. accIdList.add(con1.accountid);
  7. }
  8. }
  9. if(Trigger.isDelete){
  10. For(Contact con1 : Trigger.old){
  11. accIdList.add(con1.accountid);
  12. }
  13. }
  14. List<Account> accUpdateList = new List<Account>();
  15. For(Account acc : [SELECT Contact_Recs__c,(SELECT id FROM Contacts) FROM Account WHERE id =: accIdList]){
  16. acc.Contact_Recs__c = acc.Contacts.size();
  17. accUpdateList.add(acc);
  18. }
  19. try{
  20. update accUpdateList;
  21. }Catch(Exception e){
  22. System.debug('Exception :'+e.getMessage());
  23. }
  24. }
  25.  
  26. public class OpportunityCustomRollup {
  27.  
  28. public static void CountRollup(List<Opportunity> lstOpportunity){
  29.  
  30. set<id> oppIds = new set<id>();
  31. map<string, integer> classroomIDToDeskCountMap = new map<string, integer>();
  32. id objrecordtypeid = [SELECT Id FROM RecordType WHERE DeveloperName ='Fund_Raising'].Id;
  33. double amount = 0;
  34.  
  35. try {
  36. for (Opportunity objOpportunity : lstOpportunity){
  37. oppIds.add(objOpportunity.Fund__c);
  38. }
  39.  
  40. Fund__c objfund = [SELECT Id, Total_opportunity_amount__c FROM Fund__c WHERE Id = :oppIds];
  41. List<Opportunity> list_Opportunity = [SELECT Id, Amount FROM Opportunity WHERE Fund__c = :objfund.Id and StageName = 'Closed Won' and RecordTypeId =: objrecordtypeid];
  42.  
  43.  
  44. for(Opportunity AmountOpportunity : list_Opportunity) {
  45. amount += AmountOpportunity.amount;
  46. }
  47.  
  48.  
  49. objfund.Total_opportunity_amount__c = amount;
  50. update objfund;
  51. }
  52.  
  53.  
  54. catch (Exception e) {
  55. System.debug(e);
  56. }
  57.  
  58. }
  59.  
  60. }
  61.  
  62. trigger newLeadTrigger on Opportunity (after insert , after update, after delete , after undelete) {
  63.  
  64. if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate || trigger.isUndelete)){
  65. OpportunityCustomRollup.CountRollup(Trigger.new);
  66. }
  67.  
  68. if(Trigger.isDelete)
  69. {
  70. OpportunityCustomRollup.CountRollup(Trigger.old);
  71. }
  72. }
Add Comment
Please, Sign In to add comment