+ Start a Discussion
iyappan kandasamy 4iyappan kandasamy 4 

test class for my apex code

Hi ,

This is my test class for insert a record

Parent Object :Album__c
Child object :Track__c(which has loopup relation with Album__C)

I have written the class and the test class for inserting a record in the child object...but both are giving me error....

In main program

public class instrack 
track__c al = new track__c(); 
public track__c merch(String name,string name1)  
insert al;                 
system.debug('the inserted record is:'+name);
return al;

Executed as :

instrack mc=new instrack();

Error as: Method does not exist  or incorrect signature :void merch(string) from the type instrack....

Test class
public class instracktest
static testmethod void testmerch()
track__c al = new track__c(Name='Surgical'); 
 insert al;   
         al = new track__c (Name = 'Surgical',Album__c='GullyBoy');
         Database.SaveResult result = Database.insert(al, false);
         System.assert(result.getErrors()[0].getMessage().contains('Track already exist with this'));


Error as : System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Album__c]: [Album__c]

Kindly help out on the issue..Thanks in advance...
Hi Iyyappan,

You need to provide the Album__c field with some data before inserting the track record since it is a mandatory field.