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
impalacrazy69impalacrazy69 

test class for new trigger

Ive never really written a test class before so a little stuck trying to look at old ones to figure out what i need in order to test. Can anyone help. the class wont save saying the "Variable does not exist: tcontact.id"

 

@IsTest

public class Lead_Campaign_Mid_Market_Test{
static testMethod void testCampMember() {


// Create testing Camp, Lead, Contact and Campaign member data 
Campaign tCampaign = new Campaign(name='testcamp');
insert tCampaign;

Lead tlead = new Lead(FirstName='SaraTester',LastName='testing',Lead_Routing_Override__c = 'Mid Market', Trigger_Assignment_Rules__c = true);
insert tlead;

Contact tcontact = new Contact(FirstName='JimTester',LastName='testing');
insert tcontact;


CampaignMember tCampMemb = new CampaignMember(campaignId=tCampaign.id,leadId=tlead.id,contactId=tcontact.id,status='Responded');
insert tCampMemb;




}
}

 

souvik9086souvik9086

In the above code that you gave there is a variable name tcontact.

 

Contact tcontact = new Contact(FirstName='JimTester',LastName='testing');
insert tcontact;


It should not come there. Is this your whole code?

Make sure that you are not using that variable before it is declared.

From the above code it looks fine.

 

 If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

impalacrazy69impalacrazy69

Yes the code shown is my entire test class.

souvik9086souvik9086

I saved it in my org. It is saved without any error. The same code.

 

Thanks