Recently I created an after insert trigger to update a field in my sponsorship object. it works so far in sandbox and has passed the unit test that I have created and has 100% code coverage. here is the code for the trigger:
trigger Donation_Updater on Opportunity (after insert) {
For(Opportunity Don : Trigger.New)
{
if(Don.Sponsorship_Contract__c != null)
{
sponsorships__c spon = [SELECT Id FROM sponsorships__c WHERE Id = :Don.Sponsorship_Contract__c LIMIT 1];
spon.Donation__c = Don.Id;
update spon;
}
}
}
The question that I have is do you guys think this trigger is ready to be ported to production? The only thing i can think of is possibly replacing the SQOL statement but I'd rather keep it in if at all possible,any other suggestions?
for
loop and make this bulk safe. Presumably your unit test also doesn't operate on 200 Opportunities and their related sponsorships or you would have seen the exception that gets thrown by this pattern.