You need to sign in to do that
Don't have an account?
Alex Groag
Trigger to Update related Recurring Donations when an Opportunity is edited or Created
Hi - I'm trying to write a trigger that will update Recurring Donations when a related opportunity is created or edited. We need to map encrypted credit card fields on the opportunity to encrypted fields on the Recurring Donation. I'm a novice when it comes to trigger/apex and have been trying to repurpose from other people's post but I'm not having any luck. Below is the starting point using test checkbox fields. If we can get this to work then I can modify it for more fields. In the developer console I'm not getting any errors - but when I edit an Opportunity the Recurring Donation is not updating.
Here is the code I was using.
trigger TestRD1 on Opportunity (after insert, after update) {
List<Opportunity> opps = new List<Opportunity>();
List<npe03__Recurring_Donation__c> RDs = new List<npe03__Recurring_Donation__c>();
for (Opportunity opp : Trigger.new) {
opps = [SELECT Id, Test_Checkbox__c FROM Opportunity LIMIT 1];
RDs = [SELECT Id, Test_Checkbox__c FROM npe03__Recurring_Donation__c WHERE Id =: opp.npe03__Recurring_Donation__c];
}
for( Opportunity O : opps) {
for (npe03__Recurring_Donation__c RD: RDs){
if(O.Test_Checkbox__c== true ){
RD.Test_Checkbox__c=true;
}
}
update RDs;
}}
Here is the code I was using.
trigger TestRD1 on Opportunity (after insert, after update) {
List<Opportunity> opps = new List<Opportunity>();
List<npe03__Recurring_Donation__c> RDs = new List<npe03__Recurring_Donation__c>();
for (Opportunity opp : Trigger.new) {
opps = [SELECT Id, Test_Checkbox__c FROM Opportunity LIMIT 1];
RDs = [SELECT Id, Test_Checkbox__c FROM npe03__Recurring_Donation__c WHERE Id =: opp.npe03__Recurring_Donation__c];
}
for( Opportunity O : opps) {
for (npe03__Recurring_Donation__c RD: RDs){
if(O.Test_Checkbox__c== true ){
RD.Test_Checkbox__c=true;
}
}
update RDs;
}}
PS: Try to avoid SOQL and DML statements inside loops as it will break when the governor limit reaches.
Refer here : https://developer.salesforce.com/page/Apex_Code_Best_Practices
Regards
All Answers
PS: Try to avoid SOQL and DML statements inside loops as it will break when the governor limit reaches.
Refer here : https://developer.salesforce.com/page/Apex_Code_Best_Practices
Regards
If Opportunity Encrypted field ChargentSFA__Card_Number__c != Null, then copy field value to Recurring Donation Card_Number__c.
Thanks, really appreciate it.