我是salesforce的新手,我正在尝试为触发器编写测试类。我试着写一个测试类。
在修正测试类
时非常感谢任何帮助我正在为触发器
编写测试类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;
}
上面触发器的测试类 @isTest 公共课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];
}
}
错误:编译错误:无效的标识符:第13行第16行的Booking__cName
在此错误之后,我删除了Booking__c对象的下划线。下一个错误是
错误错误:编译错误:第14行16:16在第14行第16行的字符'_'处没有可行的替代
答案 0 :(得分:0)
在此行中预订的构造函数中,您似乎有Booking __c
而非Booking__c
(额外空格)和额外,
:
Booking __c Booking = new Booking (BookingId= bookingItemsForCancelling.Id,
Name= Booking __cName, );