You need to sign in to do that
Don't have an account?
jason_best
Trigger Design
I am very new to SF, but I'm building out a Student Recruiting App for
my org. I would love some feedback on the design of this trigger I
just created. I'm not sure how much background you need on the data
structure of the app to provide feedback, but I will give you a basic
overview.
- Education Object is detail to to Contact - used to show all schools a
prospect has attended. - Education has Account Lookup field for link back to School(Account
Record) - Enrollment is Child to Contact - used to Inquiry through graduation
for students - Application is Child to Enrollment
- Document is Child to Application
I hope that's enough to make sense of it all. Here is the trigger. It works just fine, but I
would love to hear from the experts if this looks like it will scale
well and any other feedback you are willing to offer.
trigger CreateDocuments on Application__c (after insert) { List<Document__c> createdocument = new List <Document__c> {}; for (Application__c app : trigger.new) { List<Contact> c=[SELECT Id,Name FROM Contact WHERE Id=:app.Contact__c]; List<Education__c> ed = [SELECT School__c FROM Education__c WHERE Student__c=:c]; if(app.Recieved_Method__c <> 'Online'){ for(Education__c e : ed){ createdocument.add(new Document__c ( Name = 'Transcript', Application__c =app.id,School__c=e.School__c,Contact__c=app.Contact__c)); } createdocument.add(new Document__c ( Name = 'Recommendation 1', Application__c = app.id,Contact__c=app.Contact__c)); createdocument.add(new Document__c ( Name = 'Recommendation 2', Application__c = app.id,Contact__c=app.Contact__c)); } } try { insert createdocument; } catch (Exception Ex) { system.debug(Ex); }
Hi Jason,
My first question to you is that is the trigger bulk enabled. Have you tested with a quiet a more number of records.
I think you might hit the apex governor limits because of the below said reason.
Apply the changes accordingly and check how your trigger works.
And do let me know if any concerns.
All Answers
Hi Jason,
My first question to you is that is the trigger bulk enabled. Have you tested with a quiet a more number of records.
I think you might hit the apex governor limits because of the below said reason.
Apply the changes accordingly and check how your trigger works.
And do let me know if any concerns.
Thanks for the feedback. Governor limits is exactly what I was wondering about. I have made this change and it works wonderfully. (side note: We could only dream at this point that we would need to worry about managing thousands of applications. But that's a marketing issue)
I really appreciate you taking the time to school this newbie.
Jason