• Keegan Phillips
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Newbie to coding here and I'm trying to make a test class. Here's the code I've currently got:
@IsTest
public class tempTestPBchanges {
    
    /* Test class for making sure Assignment PB replacements are the same as the three PBs that existed before.
* Temporary, for use only in Dev sandbox, not to be deployed. If you want to save the code, copy it into a text file.
*/
    
    public static string createTestApprenticeship() {
        //------ Set up Test Data
        
        //Create a School District (may not be necessary, as school district is only required in the UI?)
        
        //Create a School
        Account testSchoolAccount = new Account(Name = 'Test school');
        insert testSchoolAccount;
        
        //Create a Company
        Account testCompanyAccount = new Account (Name='Test Company');
        insert testCompanyAccount;
        
        //Create a Mentor
        Contact testMentorContact = new Contact (
            npsp__Primary_Affiliation__c = testCompanyAccount.Id,
            FirstName = 'Test', 
            LastName = 'MentorOne',
            Creativity__c = 2,
            Communication__c = 2,
            Following_directions__c = 0,
            Helping_Others__c = 0,
            Influencing_others__c = 0,
            Operating_Machines__c = 0,
            Planning__c = 0,
            Reading_and_Writing__c = 0,
            Research_and_Logic__c = 0,
            Singing_and_acting__c = 0,
            Solving_problems__c = 0,
            Understanding_Shapes__c = 0,
            Working_with_others__c = 0,
            Attention_to_detail__c = 0,
            Career_Area_Industry__c = 'Entertainment'
        );
        insert testMentorContact;
        
        //Create a Catalog Entry
        Catalog_Entry__c testCatalogEntry1 = new Catalog_Entry__c(
            Name = 'Test MentorOne Catalog Entry', 
            Account__c = testCompanyAccount.Id,
            Primary_Mentor_Lookup__c = testMentorContact.Id
        );
        insert testCatalogEntry1;
        
        //Create a Student at the school
        Contact testStudentContact = new Contact (
            FirstName='Test', 
            LastName='Student', 
            npsp__Primary_Affiliation__c=testSchoolAccount.Id);
        insert testStudentContact;
        
        //Create a Program at the school
        yat__Program__c testProgram = new yat__Program__c(
            Name = 'Test Program SY19', 
            yat__Program_Year__c='SY19'
        );
        insert testProgram;
        
        //Create a Mentorship
        Apprenticeship__c testMentorship = new Apprenticeship__c(
            Name = 'Test Student Mentorship',
            Program__c = testProgram.Id,
            School__c = testSchoolAccount.Id,
            Student_Name__c = testStudentContact.Id,
            StageName__c = 'Student Requested',
            Creativity__c = 2,
            Communication__c = 2,
            Following_directions__c = 2,
            Helping_Others_New__c = 2,
            Influencing_others__c = 2,
            Operating_Machines__c = 2,
            Planning__c = 2,
            Reading_and_Writing__c = 2,
            Research_and_Logic__c = 2,
            Singing_and_acting__c = 2,
            Solving_problems__c = 2,
            Understanding_Shapes__c = 2,
            Working_with_others__c = 2,
            Attention_to_detail__c = 2,
            Innovative__c = 2,
            Creative__c = 2,
            Building__c = 2,
            Organization__c = 2,
            Scientific__c = 2,
            Social__c = 2
        );
        insert testMentorship;
        
        //------ Here ends the basic data creation
        
        //------ Testing the PBs
        //Create an Assignment
        Assignment_New__c testAssign = new Assignment_New__c (
            Name = 'testAssign',
            Catalogue_Entry__c = testCatalogEntry1.Id,
            Apprenticeship_Name__c = testMentorship.Id,
            Status__c = 'Possible Match'
        );
        insert testAssign;
        
    //Got to have a return for this method. Right now it's the assignment status. 
    //But it probably should be the Id so you can work with it later. But I can't make the system asserts work if it's an Id.        
        return testAssign.Status__c;
    }
    
    //Test 1: Assert that Assignment is not updated by the IsNew portions of the PB because it was not in the Matched Stage
    @isTest
    public static void testInsertAssignment() {
        String testAssignStatus = createTestApprenticeship();
        System.assertequals('Possible Match', testAssignStatus);
    }
Right now createTestApprenticeship() returns a string, the Status__c field of the inserted Assignment. But I would prefer to have it return an Id. Then in the test method I think I should be able to get the Status__c of that inserted Assignment by just using testAssignStatus.Status__c
But when I switch the return of the createTestApprenticeship() method to be Id, change the last line of that method to be 
return testAssign.Id;

and then change the system.assert to be
System.assertequals('Possible Match', testAssignStatus);
it won't compile. I get the error on that last line, in fact.

What am I missing, please?