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
Kamaldeep SehrawatKamaldeep Sehrawat 

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 :
    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 

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;


        update s;

        Account a = [SELECT Id FROM Account WHERE Account.Name = 'GGU - International Admissions & Advising'];

        system.assertEquals(AccountId, a.Id);



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.


can you elaborate the problem that you are facing when you try to move this to prod?