GYM Management System

Cult Filt

Gym Management System

1. Project Overview

The CultFit Gym Management System is built on the Salesforce platform using Apex triggers and custom objects. 
It automates the process of onboarding new members by: 

  • Creating Member records. 
  • Automatically assigning a default trainer when a new member joins. 
  • Creating a Session record scheduled for the next day. 
  • Setting the session status to Schedule without manual work. 

 

2. Objects and Fields

Objects and Fields
Field Label API Name Data Type Description
Member Name
Name
Text
The full name of the member.
Mobile Number
Mobile__c
Text
The member’s mobile phone number for contact purposes.
Email
Email__c
Email
The member’s email address, used for communication or notifications.
Join Date
Join_Date__c
Date
The date when the member joined or registered in the system.

Trainer Object (Trainer__c)

Field Label API Name Data Type Description
Trainer Name
Name
Text
The full name of the trainer.
Specialization
Specialization__c
Picklist
The trainer’s area of expertise (e.g., Yoga, Swimming, Fitness, Cooking, etc.).
Trainer Object

Session Object (Session__c)

Field Label API Name Data Type Description
Session Number
Name
Auto Number
A system-generated unique number assigned to each session record.
Member
Member__c
Lookup
Lookup to Member__c, linking the session to the participating member.
Trainer
Trainer__c
Lookup
Lookup to Trainer__c, linking the session to the assigned trainer.
Date
Date__c
Date
The scheduled date of the session.
Status
Status__c
Picklist
The current status of the session (Scheduled, Completed, or Cancelled).
Session Object

3. Business Logic Implemented

  • Assign Default Trainer: When a new member is added, the system automatically assigns the first available trainer. 
  • Create Session: A session is created for the next day with Status = “Scheduled”. 

4. Apex Trigger

This trigger runs on the Member__c object and executes after insert. 

Go to Setup 

  • Click the ⚙️ Gear icon (top-right corner). 
  • Select Setup. 

Search for Apex Triggers 

  • In the Quick Find search bar, type Apex Triggers. 
  • Click on Apex Triggers under Custom Code. 

Click New 

  • On the Apex Triggers page, click the New button. 

Select the Object 

  • From the dropdown, select Member__c (because the trigger runs on this object). 

Enter Trigger Name and Events 

  • Trigger Name: AssignDefaultTrainer 
  • Object: Member__c 
  • Events: choose after insert (since it should run after a member record is created). 

Write the Trigger Code 

  • Copy-paste the trigger code into the editor: 

AssignDefaultTrainer.trigger

trigger AssignDefaultTrainer on Member__c (after insert) { 

    List<Trainer__c> trainers = [SELECT Id FROM Trainer__c LIMIT 1]; 

    if (!trainers.isEmpty()) { 

        List<Session__c> sessionsToInsert = new List<Session__c>(); 

        for (Member__c mem : Trigger.new) { 

            Session__c ses = new Session__c(); 

            ses.Member__c = mem.Id; 

            ses.Trainer__c = trainers[0].Id; 

            ses.Date__c = Date.today().addDays(1); 

            ses.Status__c = ‘Scheduled’; 

            sessionsToInsert.add(ses); 

        } 

        insert sessionsToInsert; 

    } 

AssignDefaultTrainer.trigger

  Click Save 

  • If there are no syntax errors, Salesforce will save the trigger successfully. 

  Test the Trigger 

  • Create a new Member__c record. 
  • After saving, check Session__c records → You should see a new session created automatically: 
  • Linked to the Member 
  • Assigned to the Trainer (first one found) 
  • Date = Tomorrow 
  • Status = “Scheduled” 

 

Explanation:

  • Query Trainer: Fetch the first available trainer. 
  • Loop through Members: For every new member, create a session. 
  • Set Values: Assign Member, Trainer, Date = Tomorrow, Status = Scheduled. 
  • Bulk Insert: Insert all session records in a single DML operation. 

5. Test Class

  • AssignDefaultTrainerTest 

@isTest 

public class AssignDefaultTrainerTest { 

 

    @isTest 

    static void testAssignDefaultTrainer() { 

         

        // Create a Trainer record 

        Trainer__c trainer = new Trainer__c(Name = ‘John Trainer’, Specialization__c = ‘Fitness’); 

        insert trainer; 

 

        // Create a Member record 

        Member__c member = new Member__c(Name = ‘Test Member’, Mobile__c = ‘9876543210’, Email__c = ‘test@test.com’); 

        insert member; 

 

        // Fetch the created session 

        Session__c session = [SELECT Member__c, Trainer__c, Date__c, Status__c FROM Session__c WHERE Member__c = :member.Id LIMIT 1]; 

 

        // Validate Session Details 

        System.assertEquals(member.Id, session.Member__c, ‘Member should match’); 

        System.assertEquals(trainer.Id, session.Trainer__c, ‘Trainer should match’); 

        System.assertEquals(‘Scheduled’, session.Status__c, ‘Status should be Scheduled’); 

        System.assertEquals(Date.today().addDays(1), session.Date__c, ‘Date should be tomorrow’); 

    } 

} 

 

Explanation of Test Class

1. @isTest Marks this class as a test class.

2. Creates a Trainer record.

3. Creates a member record → triggers AssignDefaultTrainer logic.

4. Queries the Session created automatically.

5. Validates:

Member linked correctly.

Trainer assigned.

Status = Scheduled.

Date = Tomorrow.

This ensures that the trigger works properly and is 100% covered.

Test Class

6. Key Features

  • Automatically assigns a default trainer when a new member joins. 
  • Creates a session for the next day without manual input. 
  • Ensures data consistency and automation using Apex triggers. 
  • Fully tested with a unit test class for deployment. 

7. Conclusion

The FitPro Gym Management System simplifies and automates the onboarding process for gym members by leveraging Salesforce Apex triggers. 
With this solution: 

  • Trainers are automatically assigned to new members. 
  • Initial sessions are scheduled for the next day without manual effort. 
  • The process ensures accuracy, consistency, and time savings for gym staff. 

This project demonstrates how Salesforce automation can be effectively used to manage real-world business scenarios like gym membership and session scheduling. It can be further enhanced by: 

  • Round-robin trainer allocation for fair distribution. 
  • Specialization-based assignment to match member goals. 
  • Notifications and reminders for members and trainers. 

Course Video