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
Chad MoutesChad Moutes 

Apex Test Class to Create a new Record

I'm trying to create a test class that is going to create a new "Assigned_BDM__c" and I keep getting this error: Compile Error: Illegal assignment from String to Date at line 12 column 5.

Here is my test class:
 
@isTest

public class TestActiveBDMsTriggerOnInsert {

    static testMethod void insertNewBDM() {
    
    Assigned_BDM__c bdmToCreate = new Assigned_BDM__c();
    
    bdmToCreate.BDM_Assigned1__c = 'a0Ki0000009XKgM';
    bdmToCreate.CampaignX__c = 'a0Ei000000Y24Jh';
    bdmToCreate.Account_Name__c = '001i000000box1d';
    bdmToCreate.Start_Date__c = '1/28/2015';
    
    insert bdmToCreate;
    
    }
    
}

Any help would be greatly appreciated.
Best Answer chosen by Chad Moutes
Balaji Chowdary GarapatiBalaji Chowdary Garapati
Change the following statement
bdmToCreate.Start_Date__c = '1/28/2015';

to

bdmToCreate.Start_Date__c =Date.ValueOf('2015-28-01');
or to dynamically fetch the date use:

bdmToCreate.Start_Date__c = Date.Today();

A small suggestion, instead of you creating records and assigning ids, you are assigning the record ids directly which isnt the right way.,

for eg., to give the account id, you need to first insert account

Account acc=new Account(Name='Sample Name');
insert acc;

and you need to assign it!:

bdmToCreate.Account_Name__c = acc.id;

Hope it helps.,

Thanks,
balaji