You need to sign in to do that
Don't have an account?
subodh chaturvedi 17
My test class is not giving any error & running successfully but while checking code coverage it is giving none
I mentioned my class with respective test class. please let me know where I am doing wrong.
My class is calling in a trigger which fires when my support Request(object) Record is approved by the approver through the standard approval process. when the record is approved the trigger automatically create an Event record. below is the class with test class .
Public class AutoCreateEvent
{
Public static void createNewEvent(List<DealSupportRequest__c> dsreq, Map<Id, DealSupportRequest__c> oldDsreqMap)
{
List<Event> EventRec = new List<Event>();
RecordType SuppReqRecordType = [SELECT Id
FROM RecordType
WHERE SobjectType = 'DealSupportRequest__c' AND DeveloperName = 'PSCUOnsiteSupport'
LIMIT 1];
for(DealSupportRequest__c ds:dsreq)
{
if((ds.Is_approved__c==true && ds.RecordtypeId==SuppReqRecordType.Id) && (ds.Is_approved__c != oldDsreqMap.get(ds.Id).Is_approved__c) )
{
Event e = new Event();
e.WhatId = ds.Account__c;
e.Type = 'On-Site at PSCU';
e.Status__c = 'Scheduled';
e.OwnerId = ds.Ownerid;
e.Subject_Custom__c =ds.Purpose__c;
e.Description = ds.OtherPurpose__c;
e.StartDateTime =ds.StartDateTime__c;
e.EndDateTime = ds.EndDateTime__c;
e.LocationCallInInfo__c = ds.CampusLocation__c;
e.Support_Request__c = ds.Id;
EventRec.add(e);
}
}
If(EventRec.size()>0)
Insert EventRec;
}
}
Test class:
@IsTest
public class AutoCreateEvent_Test {
static testmethod void CreateEvent(){
Test.startTest();
User u = new User(
ProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator'].Id,
LastName = 'last',
Email = 'puser000@amamama.com',
Username = 'puser000@amamama.com' + System.currentTimeMillis(),
CompanyName = 'TEST',
Title = 'title',
Alias = 'alias',
TimeZoneSidKey = 'America/Los_Angeles',
EmailEncodingKey = 'UTF-8',
LanguageLocaleKey = 'en_US',
LocaleSidKey = 'en_US',
EmployeeNumber='1'
);
insert u;
List<Event> EventRec = new List<Event>();
Account a = new Account(Name='1st Community CU',Membership_Defined__c='Member',Type='Client', ownerid=u.id );
Insert a;
DealSupportRequest__c dsr = new DealSupportRequest__c(Account__c=a.Id,StartDateTime__c=system.now(),EndDateTime__c=system.now().addDays(1),ownerid=a.Ownerid);
Insert dsr;
Event e = new Event();
e.WhatId=a.Id;
e.Type = 'On-Site at PSCU';
e.Status__c = 'Scheduled';
e.OwnerId = dsr.Ownerid;
// e.Support_Request__c=dsr.Id;
e.StartDateTime =dsr.StartDateTime__c;
e.EndDateTime = dsr.EndDateTime__c;
EventRec.add(e);
insert EventRec;
Test.stopTest() ;
}
}
My class is calling in a trigger which fires when my support Request(object) Record is approved by the approver through the standard approval process. when the record is approved the trigger automatically create an Event record. below is the class with test class .
Public class AutoCreateEvent
{
Public static void createNewEvent(List<DealSupportRequest__c> dsreq, Map<Id, DealSupportRequest__c> oldDsreqMap)
{
List<Event> EventRec = new List<Event>();
RecordType SuppReqRecordType = [SELECT Id
FROM RecordType
WHERE SobjectType = 'DealSupportRequest__c' AND DeveloperName = 'PSCUOnsiteSupport'
LIMIT 1];
for(DealSupportRequest__c ds:dsreq)
{
if((ds.Is_approved__c==true && ds.RecordtypeId==SuppReqRecordType.Id) && (ds.Is_approved__c != oldDsreqMap.get(ds.Id).Is_approved__c) )
{
Event e = new Event();
e.WhatId = ds.Account__c;
e.Type = 'On-Site at PSCU';
e.Status__c = 'Scheduled';
e.OwnerId = ds.Ownerid;
e.Subject_Custom__c =ds.Purpose__c;
e.Description = ds.OtherPurpose__c;
e.StartDateTime =ds.StartDateTime__c;
e.EndDateTime = ds.EndDateTime__c;
e.LocationCallInInfo__c = ds.CampusLocation__c;
e.Support_Request__c = ds.Id;
EventRec.add(e);
}
}
If(EventRec.size()>0)
Insert EventRec;
}
}
Test class:
@IsTest
public class AutoCreateEvent_Test {
static testmethod void CreateEvent(){
Test.startTest();
User u = new User(
ProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator'].Id,
LastName = 'last',
Email = 'puser000@amamama.com',
Username = 'puser000@amamama.com' + System.currentTimeMillis(),
CompanyName = 'TEST',
Title = 'title',
Alias = 'alias',
TimeZoneSidKey = 'America/Los_Angeles',
EmailEncodingKey = 'UTF-8',
LanguageLocaleKey = 'en_US',
LocaleSidKey = 'en_US',
EmployeeNumber='1'
);
insert u;
List<Event> EventRec = new List<Event>();
Account a = new Account(Name='1st Community CU',Membership_Defined__c='Member',Type='Client', ownerid=u.id );
Insert a;
DealSupportRequest__c dsr = new DealSupportRequest__c(Account__c=a.Id,StartDateTime__c=system.now(),EndDateTime__c=system.now().addDays(1),ownerid=a.Ownerid);
Insert dsr;
Event e = new Event();
e.WhatId=a.Id;
e.Type = 'On-Site at PSCU';
e.Status__c = 'Scheduled';
e.OwnerId = dsr.Ownerid;
// e.Support_Request__c=dsr.Id;
e.StartDateTime =dsr.StartDateTime__c;
e.EndDateTime = dsr.EndDateTime__c;
EventRec.add(e);
insert EventRec;
Test.stopTest() ;
}
}
All Answers
Can you please let me know how to give a reference & where
In your AutoCreateEvent class, you have a method called createNewEvent. You need to call this method in your test class AutoCreateEvent_Test.
Right now, that is missing from your test class.
1. Unexpected token 'Map'.
2.Unexpected token 'Map'.
3. Expecting ';' but was: ','
4. Unexpected token ')'.
5.Variable does not exist: DealSupportRequest__c