You need to sign in to do that
Don't have an account?

Trigger for populating the Account Name
Hi All,
I am very new to Apex Coding and trying to create a Trigger to Update the Account Name on the Contact Object whenever the Contact meet the Specific criteria. Below is the Trigger code and test Class that I have written but I have problems in Deploying the Code in the Production Env.
trigger IAA on Contact (before insert, before update)
{
for (Contact c : Trigger.new)
{
if (c.Area_of_Interest_del__c != 'Law' && (c.Visa_Type__c == 'J-1 Exchange Visitor'||c.Visa_Type__c =='F-1 Nonimmigrant Student'||c.International_Student__c ==True))
{
Account iaa = [Select Id FROM Account WHERE Account.Name = 'GGU - International Admissions & Advising'];
c.AccountId = iaa.Id;
}
}
}
Test Class Code
@isTest
private class IAA {
@isTest static void test_method_one() {
Contact s = new Contact(Area_of_Interest_del__c = 'Accounting',Visa_Type__c = 'J-1 Exchange Visitor',FirstName = 'Test',LastName = 'IAA',Origin_Channel__c ='C-Banner',Origin_Source__c = 'Trader');
insert s;
System.assert(s.Id != null);
Campaign cam = [SELECT Id FROM Campaign WHERE Campaign.Name = 'Banner_Trader'];
System.assert(cam.Id != null);
CampaignMember cm = new CampaignMember(ContactId = s.Id, CampaignId = cam.Id, Status = 'Responded');
insert cm;
System.assert(cm.Id != null);
Id AccountId = [SELECT Id, AccountId FROM Contact WHERE Contact.Id=:s.Id].AccountId;
test.startTest();
update s;
Account a = [SELECT Id FROM Account WHERE Account.Name = 'GGU - International Admissions & Advising'];
system.assertEquals(AccountId, a.Id);
test.stopTest();
}
}
Can anybody please help in finding out where is the problem in my test class or Trigger and also help me in bulkifying and batchifying it so that I can deploy it to Production.
Thanks
Kamaldeep
I am very new to Apex Coding and trying to create a Trigger to Update the Account Name on the Contact Object whenever the Contact meet the Specific criteria. Below is the Trigger code and test Class that I have written but I have problems in Deploying the Code in the Production Env.
trigger IAA on Contact (before insert, before update)
{
for (Contact c : Trigger.new)
{
if (c.Area_of_Interest_del__c != 'Law' && (c.Visa_Type__c == 'J-1 Exchange Visitor'||c.Visa_Type__c =='F-1 Nonimmigrant Student'||c.International_Student__c ==True))
{
Account iaa = [Select Id FROM Account WHERE Account.Name = 'GGU - International Admissions & Advising'];
c.AccountId = iaa.Id;
}
}
}
Test Class Code
@isTest
private class IAA {
@isTest static void test_method_one() {
Contact s = new Contact(Area_of_Interest_del__c = 'Accounting',Visa_Type__c = 'J-1 Exchange Visitor',FirstName = 'Test',LastName = 'IAA',Origin_Channel__c ='C-Banner',Origin_Source__c = 'Trader');
insert s;
System.assert(s.Id != null);
Campaign cam = [SELECT Id FROM Campaign WHERE Campaign.Name = 'Banner_Trader'];
System.assert(cam.Id != null);
CampaignMember cm = new CampaignMember(ContactId = s.Id, CampaignId = cam.Id, Status = 'Responded');
insert cm;
System.assert(cm.Id != null);
Id AccountId = [SELECT Id, AccountId FROM Contact WHERE Contact.Id=:s.Id].AccountId;
test.startTest();
update s;
Account a = [SELECT Id FROM Account WHERE Account.Name = 'GGU - International Admissions & Advising'];
system.assertEquals(AccountId, a.Id);
test.stopTest();
}
}
Can anybody please help in finding out where is the problem in my test class or Trigger and also help me in bulkifying and batchifying it so that I can deploy it to Production.
Thanks
Kamaldeep
can you elaborate the problem that you are facing when you try to move this to prod?