Reputation: 13
I am fairly new to salesforce and i am trying to write a test class for a trigger. I tried writing a test class.
Any help is much appreciated in correcting the test class
I am writing a test class for the Trigger Below
Trigger Booking on Booking__c (after insert, after update) {
Set<Id> cancelledBookingIds = new Set<Id>();
for (Booking__c booking: Trigger.new) {
if (booking.Booking_Type__c == 'cancelled') {
cancelledBookingIds.add(booking.id);
}
}
List<Booking_Item__c> bookingItemsForCancelling = [SELECT Booking_Type__c
FROM Booking_Item__c
WHERE Booking__c IN: cancelledBookingIds];
for (Booking_Item__c item: bookingItemsForCancelling) {
item.Booking_Type__c = 'cancelled';
}
update bookingItemsForCancelling;
}
Test Class for the trigger above @isTest Public class BookingTest {
static testMethod void testBookingStatus() {
Booking_Item__c bookingItemsForCancelling = new Booking_Item__c ( Name='TestBookingItem');
insert bookingItemsForCancelling ;
// Set up the Booking_Item__c record.
bookingItemsForCancelling = [SELECT Booking_Type__c
FROM Booking_Item__c
WHERE Booking__c IN: cancelledBookingIds];
System.assertEquals(null, bookingItemsForCancelling . Booking_Item__c);
// Set up the Booking__c record.
String Booking__cName= 'My Booking';
Booking __c Booking = new Booking (BookingId= bookingItemsForCancelling.Id,
Name= Booking __cName, );
// Cause the Trigger to execute.
insert Booking;
// Verify that the results are as expected.
bookingItemsForCancelling = [SELECT Booking_Type__c
FROM Booking_Item__c
WHERE Booking__c IN: cancelledBookingIds];
}
}
Error: Compile Error: Invalid identifier: Booking__cName at line 13 column 16
After this error i removed the underscore on Booking__c Object. The next error is
Error Error: Compile Error: line 14:16 no viable alternative at character '_' at line 14 column 16
Upvotes: 0
Views: 187
Reputation: 1
It looks like you have Booking __c
instead of Booking__c
(extra space) and an extra ,
in the constructor for the Booking in this line:
Booking __c Booking = new Booking (BookingId= bookingItemsForCancelling.Id,
Name= Booking __cName, );
Upvotes: 0