|
Post by djroot on Mar 27, 2013 8:31:20 GMT -5
Great demo last night! I can't believe I am the first person to post to this forum! #awesome I am more of an admin/coder than a software developer, but have been developing a lot of visualforce pages and associated code. I have a custom object and a trigger that works in the sandbox. I need to get over the hump of test classes so I can get code coverage. Can someone give me an example of a test class for these triggers? trigger expenseInsertOwner on Expenses__c (before insert, before update) { for (Expenses__c p: trigger.new) { p.ownerId=p.name__c; } } trigger expenseUpdateOwner on Expenses__c (before update) { // Creating the instance of the custom object Expenses__c p=new Expenses__c(); // Creating the list of object list< Expenses__c> u = new list< Expenses__c>(); //loop containing the all new value the record for (Expenses__c e: trigger.new) { //change the field using mapping method trigger.newmap.get(e.id).ownerId=trigger.newmap.get(e.id).name__c; } }
|
|
|
Post by Admin on Mar 27, 2013 15:37:59 GMT -5
Hey there what is this tigger supposed to do?
|
|
|
Post by enablepath on Mar 27, 2013 15:59:19 GMT -5
In general, your test classes are supposed to run through the lines of code that you have created to make sure each one runs without a problem (i.e. Exception), and that it returns the intended result. So for the above code, in your test Class and test method, you would need to create an Expense__c record and simply insert it. for example:
/*** Test Method Example - To be put in a test Class ***/ @istest public static void TestExpenseInsert(){ //here we start the test context Test.startTest();
//lets create a sample Expense Record Expense__c testRecord = new Expense__c(); //set your record values... testRecord.Name = 'blah' // set whatever values your trigger needs // now attempt the insert insert testRecord;
//now you can test for expected values System.assertEquals('blah',testRecord.Name);
//here we stop the test context Test.stopTest(); }
Your question is really beyond the scope of this forum. Question here should really be specifically geared toward using the Soapbox Service in conjunction with the Force.com connector package. But I hope this helps you.
|
|
|
Post by djroot on Mar 27, 2013 17:22:58 GMT -5
Admin: the triggers change the owner of the expense to the person that incurred the expense, which is a user look up field. This helps accounting speed up expense entry by not having to click "change owner" and go through that process.
Enablepath: thanks for the help, I'll give that a try. I hear ya, and will try to keep my posts a bit more SOAPBox centric. I will be working on a proof of concept with the box, and hopefully this will help me over that hump!
|
|
|
Post by enablepath on Apr 3, 2013 7:26:59 GMT -5
No problem djroot - here to help. Let me know if that worked for you. Remember - the method above needs to be in a class - preferrably a test class in order to run. if it helps you, thumbs up the post. And please, keep posting! Looking forward to hearing about your proof of concept!
|
|