• parks0231
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies

My organization hired a consultant to do some customizations. One of the things they did was to write a trigger that runs after a gift is created or updated and to update fields on the associated contact's record. But, it is failing when I try to update more than 10ish records at a time, either via the data loader or via bulk update from lists. 

 

Can someone either: 

1 - Look at this code and tell me how I can update it so it can handle bulk updates, or 

2 - Tell me how to temporarily disable this trigger so I can update the records? 

 

Any help would be grately appreciated!!!!!

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 trigger updateGiftInformation on Opportunity (after update, after insert) {
  
  for(Opportunity o : Trigger.new){
         
         Decimal accountLargestAmount = 0.0;
         Decimal contactLargestAmount = 0.0;
         Integer accountCount = 0;
         Integer contactCount = 0;
         
         Account accountToUpdate = [select Id, Largest_Gift_Date__c, Last_Gift_Given__c, Largest_Gift_Given__c 
                         from Account
                         where Id = :o.AccountId];
      
      Contact contactToUpdate = [select Id, Largest_Gift_Date__c, Largest_Gift_Given__c, Last_Gift_Date__c,
                         Last_Gift_Given__c
                     from Contact
                     where Id = :o.Contact__c];    
      
      Opportunity[] contactOpps = [select CloseDate, Amount 
                           from Opportunity
                            where Contact__c = :o.Contact__c and
                            StageName = 'Posted'
                            order by CloseDate desc];
      
        
      if(o.AccountId != '0018000000U9G5W' || o.AccountId !=null){
         
                  
           Opportunity[] opps = [select CloseDate, Amount 
                        from Opportunity
                         where AccountId = :o.AccountId and
                         StageName = 'Posted'
                         order by CloseDate desc];
           
           for(Opportunity currOpp : opps){
             
             Decimal tempCurrency = currOpp.Amount;
             
             if(tempCurrency > accountLargestAmount){
               accountToUpdate.Largest_Gift_Date__c = currOpp.CloseDate;
               accountLargestAmount = tempCurrency;
             }
             
             if(accountCount == 0){
               accountToUpdate.Last_Gift_Given__c = currOpp.Amount;
               accountCount++;
             }             
               
           }
      }
         
         update accountToUpdate;
         
         for(Opportunity currOpp : contactOpps){
           
           Decimal tempCurrency = currOpp.Amount;
           
           if(tempCurrency > contactLargestAmount){
             contactToUpdate.Largest_Gift_Date__c = currOpp.CloseDate;
             contactToUpdate.Largest_Gift_Given__c = tempCurrency;
             contactLargestAmount = tempCurrency;
           }
           
           if(contactCount == 0){
             contactToUpdate.Last_Gift_Given__c = currOpp.Amount;
             contactToUpdate.Last_Gift_Date__c = currOpp.CloseDate;
             contactCount++;
           }
             
           
         }
         
         update contactToUpdate;
  }
}

I want to create a new button with content source URL. Where is there a reference guide for this?

 

I want to do something similar to this: http://sputnikmoment.com/blog/custom-button#.UaebF0C1GSp, but instead of creating a new opportunity I want it to edit the contact with some pre-loaded fields. I have no idea how to build that URL though. 

 

Also, something on getting started with buttons would be helpful, I can find bits and pieces, but nothing that walks you through creating the different types of buttons and provides reference for the development / code needed.

 

Help much appreciated!

Thanks.

I am starting to implement campaigns at my organization, and there are some things that seem like double work. I'm wondering if I should be setting up workflow rules or if I'm using fields in the wrong way.

 

So, let's say we have campaign "Spring 2013" and I get a response back in the form of revenue from the organization / contact that was sent the campaign. 

 

When I get the check in, I enter it as an opportunity in SF, adding Spring 2013 as primary campaign source and then separately I have to go into the contact record and mark the campaign member as responded. This seems weird and redundant.

My organization hired a consultant to do some customizations. One of the things they did was to write a trigger that runs after a gift is created or updated and to update fields on the associated contact's record. But, it is failing when I try to update more than 10ish records at a time, either via the data loader or via bulk update from lists. 

 

Can someone either: 

1 - Look at this code and tell me how I can update it so it can handle bulk updates, or 

2 - Tell me how to temporarily disable this trigger so I can update the records? 

 

Any help would be grately appreciated!!!!!

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 trigger updateGiftInformation on Opportunity (after update, after insert) {
  
  for(Opportunity o : Trigger.new){
         
         Decimal accountLargestAmount = 0.0;
         Decimal contactLargestAmount = 0.0;
         Integer accountCount = 0;
         Integer contactCount = 0;
         
         Account accountToUpdate = [select Id, Largest_Gift_Date__c, Last_Gift_Given__c, Largest_Gift_Given__c 
                         from Account
                         where Id = :o.AccountId];
      
      Contact contactToUpdate = [select Id, Largest_Gift_Date__c, Largest_Gift_Given__c, Last_Gift_Date__c,
                         Last_Gift_Given__c
                     from Contact
                     where Id = :o.Contact__c];    
      
      Opportunity[] contactOpps = [select CloseDate, Amount 
                           from Opportunity
                            where Contact__c = :o.Contact__c and
                            StageName = 'Posted'
                            order by CloseDate desc];
      
        
      if(o.AccountId != '0018000000U9G5W' || o.AccountId !=null){
         
                  
           Opportunity[] opps = [select CloseDate, Amount 
                        from Opportunity
                         where AccountId = :o.AccountId and
                         StageName = 'Posted'
                         order by CloseDate desc];
           
           for(Opportunity currOpp : opps){
             
             Decimal tempCurrency = currOpp.Amount;
             
             if(tempCurrency > accountLargestAmount){
               accountToUpdate.Largest_Gift_Date__c = currOpp.CloseDate;
               accountLargestAmount = tempCurrency;
             }
             
             if(accountCount == 0){
               accountToUpdate.Last_Gift_Given__c = currOpp.Amount;
               accountCount++;
             }             
               
           }
      }
         
         update accountToUpdate;
         
         for(Opportunity currOpp : contactOpps){
           
           Decimal tempCurrency = currOpp.Amount;
           
           if(tempCurrency > contactLargestAmount){
             contactToUpdate.Largest_Gift_Date__c = currOpp.CloseDate;
             contactToUpdate.Largest_Gift_Given__c = tempCurrency;
             contactLargestAmount = tempCurrency;
           }
           
           if(contactCount == 0){
             contactToUpdate.Last_Gift_Given__c = currOpp.Amount;
             contactToUpdate.Last_Gift_Date__c = currOpp.CloseDate;
             contactCount++;
           }
             
           
         }
         
         update contactToUpdate;
  }
}