• Iyappan Kandasamy 8
  • 0 Points
  • Member since 2019

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 1
Hi...Actually I have written 2 triggers and I need test class for these two triggers...
1. Trigger to update contact description whenever account description is updated with the same value of account description...

trigger acc on account(after update)
set<id> accids = new set<id>();
for(account a : trigger.new)
list<contact> conlist=[select id,account.description, description from contact where accountid=: accids];
for (contact c: conlist)
update conlist;

2.) Whenever account is created then create contact with the account details ...

trigger createcon on account(after insert)
list<contact> conlist = new list<contact>();
for (account a:trigger.new)
contact c = new contact();
c.lastname= a.name;
insert conlist;

Kindly need test classes for the above 2 triggers. 
Any help on writing the test classes would be of great help....Thanks...
Thanks in advance...
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...