[go: up one dir, main page]

0% found this document useful (0 votes)
179 views11 pages

Parking Management Solution

Uploaded by

mahendra bhamare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
179 views11 pages

Parking Management Solution

Uploaded by

mahendra bhamare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

In the Parking Management Solution, the following custom objects will be created, along with the

relationships between them:

Custom Objects and Relationships

1. Parking Slot (Custom Object)

 API Name: ParkingSlot__c

 Purpose: Represents a parking slot in Serene Township, whether free or occupied.

 Fields:

o Name (Auto-generated Alphanumeric ID)

o Status__c (Picklist: "Free", "Occupied")

o Account__c (Lookup to Account) – Links the parking slot to the entity it belongs to
(e.g., Serene High).

o Owner__c (Lookup to User) – Used for assigning the slot to a Security Guard Queue.

Relationship:

 Parent: Account (Lookup relationship)

 Child: Can be linked to multiple Vehicle__c records (via the Vehicle's lookup field).

2. Vehicle (Custom Object)

 API Name: Vehicle__c

 Purpose: Tracks the details of a vehicle that uses a parking slot.

 Fields:

o Name (Text: Vehicle Number)

o Entry_Time__c (DateTime: The time the vehicle enters the parking lot)

o Exit_Time__c (DateTime: The time the vehicle exits the parking lot)

o ParkingSlot__c (Lookup to ParkingSlot) – Links a vehicle to the parking slot it


occupies.

Relationship:

 Parent: ParkingSlot__c (Lookup relationship) – A vehicle occupies a parking slot.

 Parent: Account__c (Lookup relationship) – Vehicle can optionally link to the Account for
reporting purposes (optional but useful).

3. Bill (Custom Object)

 API Name: Bill__c

 Purpose: Represents a bill generated for parking.

 Fields:
o Amount__c (Currency: The total bill amount)

o Discount_Percentage__c (Number: Discount percentage if applicable)

o Discounted_Amount__c (Currency: The discounted bill amount for electric vehicles)

o Vehicle__c (Lookup to Vehicle) – Links the bill to the vehicle being billed.

o ParkingSlot__c (Lookup to ParkingSlot) – Links the bill to the parking slot.

Relationship:

 Parent: Vehicle__c (Lookup relationship) – A bill is tied to a specific vehicle.

 Parent: ParkingSlot__c (Lookup relationship) – Optionally, link the bill to the parking slot for
additional tracking.

Relationships Summary:

 Account → ParkingSlot (1 to Many):

o One Account (e.g., Serene High, Bank) can have multiple Parking Slots.

 ParkingSlot → Vehicle (1 to Many):

o One Parking Slot can have multiple Vehicle records over time, but only one active at
a time (current vehicle parked).

 Vehicle → Bill (1 to 1):

o One Vehicle record generates one Bill for the corresponding parking session.

Object Hierarchy and Use Case Flow:

1. Account represents an entity (e.g., Serene High).

2. Parking Slot records are tied to an Account, representing physical parking spaces.

3. Vehicle records track vehicles occupying parking slots, with lookup fields to both the
ParkingSlot and Account.

4. Bill records are created when a vehicle exits a parking slot, with references to the associated
Vehicle and Parking Slot.

By setting up these objects and relationships, you will create a comprehensive parking management
system in Salesforce that allows for parking slot tracking, vehicle record creation, and billing.
To implement the Parking Management Solution described in the document within Salesforce,
follow these steps:

1. Entity Management with Account Object

 Use the Account object to represent each of the 7 entities in Serene Township (e.g., Serene
High, Bank, etc.).

 Designate points of contact for each Account (e.g., Association Presidents for Serene High).

2. Visitor Parking Slots

 Add a field on the Account object for Visitor Parking Slots.

 Create an Auto-generated Flow that triggers upon updating this field. The flow will
automatically create or remove Parking Slot records to match the specified number of slots.
Ensure that only empty slots are removed, and the newest ones are prioritized for deletion.

3. Parking Slot Records and Queues

 Create a custom object for Parking Slot with unique alphanumeric IDs.

 Use Queues to assign Parking Slot records to the respective Security Guard teams based on
their associated Account.

4. Screen Flows for Parking Slot Management

 Design Screen Flows for Security Guards to update parking slot status (Occupied/Free)
without accessing the list view directly:

o Occupying a Slot: Guard selects a slot, enters the vehicle number, and the system
creates a Vehicle record or retrieves existing details. The Entry Time field should be
set.

o Freeing a Slot: Guard selects a slot, sees vehicle details, and marks the slot as free.
The Exit Time should be set, and a Bill record should be generated based on the
vehicle's parking duration.

5. Bill Calculation

 Use Apex Code to handle the billing logic:

o Free if parked for less than 2 hours.

o ₹50 per hour for parking beyond 2 hours.

o For Electric Vehicles (identified by the "EV" prefix in the vehicle number), apply a
20% discount on the calculated bill. Create two different page layouts for Bills: one
for regular vehicles and one for EVs.

6. Vehicle Records and Data Retention

 Automatically delete Vehicle records older than one year. This can be done using a
Scheduled Apex Job that runs daily to check and delete old records.

7. Dashboards and Permissions


 Implement Dashboards for Estate Managers, showing key information like parking slot status
and revenue.

 Restrict visibility:

o Estate Managers can only view and access their own Accounts.

o Only Estate Managers can view the Parking Revenue field, which shows the total
revenue generated from Bills under each Account.

8. Test Classes

 Write Apex Test Classes to ensure over 95% coverage. Include positive and negative test
scenarios for all flows and custom logic.

By following these steps, you'll build a comprehensive Parking Management solution tailored for
Serene Township using Salesforce.

4o

You said:

Please provide what what need to create ,apex class ,trigger ,screen flow

ChatGPT said:

ChatGPT

To implement the Parking Management Solution in Salesforce, the following components (Apex
classes, triggers, screen flows, etc.) need to be created:

1. Apex Classes

 BillCalculationApex:

o Logic for calculating parking charges. If the parking time is less than 2 hours, set the
bill to ₹0. Otherwise, calculate ₹50 per hour beyond 2 hours. If the vehicle is electric
(starts with "EV"), apply a 20% discount.

o Logic for generating Bill records based on the vehicle’s entry and exit times.

 VehicleDeletionScheduler:

o Scheduled job to delete Vehicle records older than one year. This should run daily
using a Scheduled Apex Class.

 ParkingSlotManagementApex:

o Logic to automatically create or delete Parking Slot records when the number of
parking slots on an Account changes. This could be a helper class invoked by a flow
or trigger.

 Test Classes:

o Test all of the above classes with both positive and negative test cases, ensuring over
95% code coverage.

2. Triggers
 VehicleTrigger:

o Trigger on the Vehicle object to check whether the vehicle is electric (i.e., if the
vehicle number starts with "EV") and apply the corresponding discount on the
generated Bill record.

 AccountParkingSlotTrigger:

o Trigger on the Account object to ensure that when the number of parking slots
changes, it either adds or deletes Parking Slot records.

3. Screen Flows

 Parking Slot Occupied Flow:

o Flow for Security Guards to mark a parking slot as "Occupied." It should:

1. Prompt the guard to select a free parking slot.

2. Prompt for the vehicle number.

3. Create a Vehicle record (or retrieve the existing one) and mark the Entry
Time.

4. Set the parking slot status to Occupied.

 Parking Slot Free Flow:

o Flow for Security Guards to mark a parking slot as "Free." It should:

1. Prompt the guard to select an occupied parking slot.

2. Display the vehicle details (number, entry time).

3. Mark the Exit Time on the vehicle record.

4. Automatically create a Bill record based on the parking duration (using the
Apex logic).

5. Set the parking slot status to Free.

 Electric Vehicle Discount Flow:

o A separate flow or subflow to apply the 20% discount when a vehicle's number starts
with "EV" during the bill generation process.

4. Queue Setup for Security Guards

 Security Guard Queues:

o Create a Queue for each Account to which Parking Slot records will be assigned.
Only Security Guards in the respective Queue can update parking slot statuses
(Occupied/Free).

5. Custom Objects and Fields

 Parking Slot:
o Custom object to track parking slot availability and statuses (Occupied/Free). Each
parking slot should have a unique alphanumeric identifier.

 Vehicle:

o Custom object to track vehicle information (e.g., vehicle number, entry time, exit
time).

 Bill:

o Custom object to track parking charges. Fields should include:

 Amount

 Discount Percentage (for EVs)

 Discounted Amount (for EVs)

6. Scheduled Apex Jobs

 Schedule the VehicleDeletionScheduler Apex class to run daily and remove vehicle records
older than one year.

7. Dashboards and Reports

 Create dashboards for Estate Managers to view:

o Total parking revenue (for their account).

o Occupied vs. Free parking slots.

 Create reports for parking revenue, electric vehicle discounts, etc.

8. Permissions

 Ensure that permissions are set for the different user types:

o Builder: Create and manage Accounts.

o Estate Manager: View only their own account records, access revenue information.

o Security Guard: View and update the status of parking slots via flows but no direct
access to slot or vehicle records.

This will cover the major requirements for the Parking Management System in Salesforce.

4o

You said:

Please provide code

ChatGPT said:

ChatGPT

Here is the Salesforce code needed for various components of the Parking Management Solution.

1. Apex Class for Bill Calculation


This class calculates the bill based on parking duration and applies a discount for electric vehicles
(EV).

apex

Copy code

public class BillCalculationApex {

public static Bill generateBill(ParkingSlot slot, Vehicle vehicle) {

Bill newBill = new Bill();

newBill.Vehicle__c = vehicle.Id;

newBill.ParkingSlot__c = slot.Id;

// Calculate time difference in hours

Long parkedDurationMillis = vehicle.Exit_Time__c.getTime() - vehicle.Entry_Time__c.getTime();

Decimal parkedDurationHours = (parkedDurationMillis / (1000 * 60 * 60));

if (parkedDurationHours < 2) {

newBill.Amount__c = 0;

} else {

newBill.Amount__c = 50 * (parkedDurationHours - 1); // ₹50 per hour after the first 2 hours

// Check if vehicle is an electric vehicle (starts with "EV")

if (vehicle.Vehicle_Number__c.startsWith('EV')) {

newBill.Discount_Percentage__c = 20;

newBill.Discounted_Amount__c = newBill.Amount__c * 0.8; // Apply 20% discount

insert newBill;

return newBill;

2. Apex Trigger for Vehicle Exit


This trigger is fired when a vehicle exits a parking slot, and it creates a bill.

apex

Copy code

trigger VehicleExitTrigger on ParkingSlot__c (after update) {

for (ParkingSlot__c slot : Trigger.new) {

if (slot.Status__c == 'Free' && Trigger.oldMap.get(slot.Id).Status__c == 'Occupied') {

// Fetch the associated vehicle

Vehicle__c vehicle = [SELECT Id, Vehicle_Number__c, Entry_Time__c, Exit_Time__c

FROM Vehicle__c

WHERE ParkingSlot__c = :slot.Id LIMIT 1];

// Set the exit time to now

vehicle.Exit_Time__c = System.now();

update vehicle;

// Generate a bill for the vehicle

BillCalculationApex.generateBill(slot, vehicle);

3. Apex Scheduled Class for Vehicle Deletion

This scheduled class will delete vehicles older than one year.

apex

Copy code

public class VehicleDeletionScheduler implements Schedulable {

public void execute(SchedulableContext sc) {

Date cutoffDate = System.today().addYears(-1);

List<Vehicle__c> oldVehicles = [SELECT Id FROM Vehicle__c WHERE Entry_Time__c


< :cutoffDate];

if (!oldVehicles.isEmpty()) {
delete oldVehicles;

You can schedule the above class using the Salesforce Scheduler like this:

apex

Copy code

VehicleDeletionScheduler job = new VehicleDeletionScheduler();

String sch = '0 0 0 * * ?'; // Daily at midnight

System.schedule('Daily Vehicle Deletion', sch, job);

4. Screen Flow (Flow) Logic

For the Security Guard to mark a parking slot as "Occupied" or "Free" using flows:

Flow: Parking Slot Occupied

1. Screen flow to select a free parking slot.

2. Screen flow to enter the vehicle number.

3. Create or update the Vehicle record.

4. Update the Parking Slot to "Occupied".

Flow: Parking Slot Free

1. Screen flow to select an occupied parking slot.

2. Show the vehicle details and confirm parking slot exit.

3. Update the vehicle Exit Time.

4. Update the Parking Slot to "Free".

5. Call the Apex Class to generate the bill.

To integrate with the Apex class:

1. In the flow, after the parking slot is set to "Free," use Apex-Defined Flow Action to call
BillCalculationApex.generateBill().

5. Trigger to Create Parking Slots Automatically

This trigger will create or remove Parking Slot records when the number of slots on an account
changes.

apex

Copy code

trigger AccountParkingSlotTrigger on Account (after update) {


for (Account acc : Trigger.new) {

Integer newSlotCount = acc.Number_of_Visitor_Parking_Slots__c;

Integer oldSlotCount = Trigger.oldMap.get(acc.Id).Number_of_Visitor_Parking_Slots__c;

if (newSlotCount > oldSlotCount) {

// Create new parking slots

for (Integer i = 0; i < (newSlotCount - oldSlotCount); i++) {

ParkingSlot__c newSlot = new ParkingSlot__c();

newSlot.Account__c = acc.Id;

newSlot.Status__c = 'Free';

newSlot.Name = acc.Name + '-P' + String.valueOf(oldSlotCount + i + 1);

insert newSlot;

} else if (newSlotCount < oldSlotCount) {

// Delete empty slots

List<ParkingSlot__c> emptySlots = [SELECT Id FROM ParkingSlot__c

WHERE Account__c = :acc.Id AND Status__c = 'Free'

ORDER BY CreatedDate DESC LIMIT : (oldSlotCount - newSlotCount)];

delete emptySlots;

6. Queue Setup for Security Guards

 Set up Queues for Security Guards and assign Parking Slot records to these queues based on
the Account.

 Ensure only Security Guards can update the Status field using record-level security and
screen flows.

7. Custom Objects and Fields

 Parking Slot (Custom Object): Tracks parking slot availability and statuses.

 Vehicle (Custom Object): Tracks vehicle information (vehicle number, entry time, exit time).

 Bill (Custom Object): Stores the parking bill details (amount, discount, etc.).

8. Dashboards and Reports


 Estate Manager Dashboard: Shows the total revenue and free/occupied parking slots.

 Revenue Report: Display revenue generated per account, split by normal vehicles and
electric vehicles.

With this code and the related configuration, you should be able to implement the Parking
Management Solution in Salesforce effectively.

4o

You might also like