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
deryckderyck 

Trying to deploy the following trigger to production

I need to deploy the following trigger into production:
 

trigger Call_Room on Case(before insert, before update) {

     Map<Id, Case[]> contactCaseMap = new Map<Id, Case[]>();

     For (Case ncase:Trigger.new) {

        Id cid = ncase.contactId;

        If (cid != NULL) {

            if(contactCaseMap.get(cid) == null) contactCaseMap.put(cid, new Case[]{});

            contactCaseMap.get(cid).add(ncase);

        }

     }

     For(Contact c:[select Call_Room_Number__c from Contact where Id IN :contactCaseMap.keySet()]) {

        for(Case ncase:contactCaseMap.get(c.id)) {

           ncase.Call_Room_Number__c = c.Call_Room_Number__c;

        }

    }

}

 

This is the only thing I need to get into the production environment for an enterprise version system.  I am useing Eclipse.  I am having trouble following the process in the Developer's Guide...can anyone help?

deryckderyck

I have since figured out a solution that worked for me.  This is what I gleamed from the developer's guide and from reading numerous posts.  I would appreciate any comments about how I might do this better in the future.  Thanks

Here are the steps I took:

1.  I installed Eclipse and the Force.com IDE

2.  I wrote the following test code (yes, I figured out that the test needed to entered as a class...and the appropriate statements to use - or at least that which seemed to work)  Keep in mind, I am a complete and utter newby

Code:
public class Call_Room_Test {
 
 Public Static testmethod void Call_Room(){
 
 //Create and account for testing
 Account a = new Account(name= 'Test1');
 insert a;
 //Create a contact associated to the account
 Contact c = new Contact(lastname = 'Jones', Emp_no__c='4321', Call_Room_Number__c='9999');
 c.accountId = a.Id;
 insert c;
 c=[Select account.name from contact where id = :c.id];
 //Create a case associated with the contact I just created
 Case d = new Case(status='open', contactid=c.id);
 insert d;
 //Test whether or not the room number I created appears appropriately in the field
 System.assertEquals('9999', [Select c.Call_Room_Number__c From Contact c where Id = :c.id].Call_Room_Number__c);
 }
}

Now, what I don't know is whether I really did any of this correctly.  I would appreciate any corrections or suggestions. 

The end result was that the code seemed to work.  I was able to test this in the sandbox and deploy it to production.  I tested it in both the sandbox and the production environment and it all seems to work.