function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mxalix258mxalix258 

Help with test class on trigger

Can anyone help me with the below test class? It is for a trigger that creates a new record in the "Onboarding" object based off criteria in the "Application__c" object.

 

Here is the test class as I have it now, but I am getting an error of "Error: Compile Error: unexpected token: 'insert' at line 13 column 8"

 

@isTest
private class OnboardingTest {

    static testMethod void myOnboardingTest() { 
        
        Account a=new Account();
        a.Name='ob test account';
        insert a;

        Contact con=new Contact();
        con.Lastname='onboarding contact';
        con.AccountId=a.Id
        insert con;

        Job__c job=new Job__c();
        job.Name='Test job1';
        insert job;

        test.startTest();

        Application__c app=new Application__c();
        app.RecordType='012C0000000Bhsc';
        app.JobId=job.Id
        insert app;

        app.Stage__c='Signed';
        update app;

        test.stopTest();
        }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
arizonaarizona

You need a semi colon after line 12

All Answers

arizonaarizona

You need a semi colon after line 12

This was selected as the best answer
mxalix258mxalix258

That worked - thank you! Is there any way to edit this code so that it covers the dml exception in the trigger as well? When i try to create another contact, and leave out information like last name, it hits the dml exception when I do the test class, but it doesn't provide any code coverage either. Any ideas?

 

@isTest
private class OnboardingTest {

    static testMethod void myOnboardingTest() { 
        
        Account a=new Account();
        a.Name='ob test account';
        insert a;

        Contact con=new Contact();
        con.Lastname='onboarding contact';
        con.AccountId=a.Id;
        insert con;

        Job__c job=new Job__c();
        job.Name='Test job1';
        insert job;

        test.startTest();

        Application__c app=new Application__c();
        app.RecordTypeId='012C0000000Bhsc';
        app.Job__c=job.Id;
        insert app;

        app.Stage__c='Signed';
        update app;

        test.stopTest();
        }
}

 

arizonaarizona

It depends on the trigger.  If the trigger is a before trigger then you can check for that but if it is an after trigger then the platform will handle the error first.