I am new in salesforce developer. Trying to create trigger.

I have 3 objects.

  1. Student
  2. Books
  3. Book Assignments

On Book Assignments object I created Master Detail relationship with Book and created lookup for Student object.

Now, when I assign new book to any of the student, count of Book should update on student object. To count the book on student object , I created one number field on Student object with name of Number.

  • 3
    Why didn't you make Book Assignment master-detail to the Student? That would give you automatic roll-up capabilities. Or, why not use DLRS so you don't have to build it yourself? Also, have you searched for existing solutions? Where are you stuck?
    – sfdcfox
    Oct 5, 2018 at 18:10
  • Actually, I want to learn ' How to use After Insert" trigger. I confuse to take id of parent object, how to get it. If you can provide the code for this, it will be helpfull Oct 5, 2018 at 18:32
  • 2
    Okay, did you look at something like this or perhaps this? There's lots of examples already here on SFSE for you to look at.
    – sfdcfox
    Oct 5, 2018 at 18:50
  • Yes, I have seen when the account is created automatically opportunity and contact is created. This type of example i have seen. But facing an issue when I am implementing my own Oct 5, 2018 at 19:07
  • 3
    Okay, well, let's see what you've tried so far. Maybe we can help you. Click edit and add in your code. It doesn't matter that it doesn't work, just show us what you've done so far.
    – sfdcfox
    Oct 5, 2018 at 19:14

1 Answer 1


The S1 instance of student will always be empty and it will never be equal to to the Name of the student in your trigger context so the check you were doing will always fail.

You need to do couple things.

  1. Get the student record Id’s if there is a student added in the book assignment and get those student records and do an update to student records.
  2. As you have the student records and book assignment records handy you can update as you want.
  • Can you please write code for me, it will be really helpful. Oct 8, 2018 at 7:03
  • Can anyone please help here? Oct 9, 2018 at 16:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .