function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Sample application


I am very new to salesforce.

I am creating a sample application where I have created 2 objects namely "Student" and "Course"


Student object has fields ( name, date of birth, address, course enrolled, start date)

Course object has fields (Course name, start date , end date, Intake )


I want to add a field in Course object for available seat which will get automatically updated (intake - number of enrollments) for any particular course.

If there are 3 course "A" , "B" and "C" with intake 20, 25 and 30, how to check available seat for any particular course.


Please provide solution in detail.







According to you you have two object a) Student b) Course


If Student object is child child or detail object of Course than it is very esay to maintain available seat for particual course.


1) If you have master detail relation ship between course and student object then you can maintain the available seat for particular course on course object:

for this you have to create a new roll up summary field on course object and select Roll up type as a count. 

2) if you have lookup relation ship then you have to write a trigger on update, insert , delete event for maintain the available seat for particular seat on studend object and also create a number type field on course object.


If this post helps you than mark it as a solution and give me kudo's 









Thanks for the reply Ashlekh,


I am very new to Salesforce it will be helpful if you guide me step by step for both the options you have given.




In this case Course should be the master object and student should be the child object.
To enable this, you will have to create a master detail field on the Student object

Goto the Student Object : New Field > Master Detail Relationship. Next and Save.

Next on the course object, i assume there is already a field called intake, which has the max number of students who can be enrolled.
So create a rollup summary field on this object to count the number of child records (student records) under a particular course.

Goto Course Object: New Field > Rollup summary > Give the names(eg: current Enrollments) > Select Summarized object as 'students' . On 'rollup type' select 'Count' > Next > Next > Save
So, on the Course object, you can see this new field which gives you the current number of enrollments for a particular course.

In order to check for available fields a simple formula field which subtracts the Intake and current Enrollments would do the task.
On Course object > New Field > Formula > Give a name (eg: Available Seats), Formula Return Type: Number (Decimal Places 0)>
Formula is :
Intake__c - Current_Enrollments__c
Next > Next > Save

Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.

Hi Manish,


The declarative option would be a better one instead of a APEX trigger, See the links below for the 1st option suggested by Ashlekh.

Try It Out: Creating Roll-Up Summary Fields


See under the best practices in the link below,


If you are trying to enforce a record limit of 25 on the parent roll-up summary field, when you add a new child record, your validation rule on the child object needs to check if the count is already 25 or greater.
AND(ISNEW(), Sample.Line_Count__c >= 25)