+ Start a Discussion
Shivani ThaparShivani Thapar 

Question about apex

Hi there... 

1) I have created an apex class in my enterprise salesforce account, and I want to deploy it now to production. So I can use it on my visual force email...

How can I do that? I wouldnt need to test it would I?
 
jp1234jp1234
You need to write a test class and use one of the migration tool (Change Set, Force.com IDE, Migration tool, etc.)  Please see http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_deploying.htm|StartTopic=Content%2Fapex_deploying.htm|SkinName=webhelp for more information.
Shivani ThaparShivani Thapar
ok thanks - so do I have to create a new apex class thats just a test of the same code? I dont understand... thx
jp1234jp1234
Yes, you need to create a test class that test your code.  There is a section on testing your code just before that deployin Apex section.
Shivani ThaparShivani Thapar
ok so i will create a new class using the same code and with the testing code...
jp1234jp1234
Am I correct in understanding that you are asking if you need to copy over the code from your existing class into the test class?  Answer is no.  Your test class should just instantiate and call appropriate methods in your existing class.
Shivani ThaparShivani Thapar
Yes I need to test this class I made... 1) are you able to maybe show me a screen shot of how to do this? I dont understand 2) are you able to maybe show me a screenshot of how to deploy it as well? thx public class FindunpaidInvoices { private final List invoices; public FindunpaidInvoices() { invoices = [select Account__c, Invoice_Date__c, Balance_Due__c from Invoice_Consulting__c where Name = 'Unpaid']; } public List getUnpaidInvoices() { return invoices; } }
jp1234jp1234
For testing something like following would work for you.  As for deployment, as I said there are many options and it is quite complicated process.  Please refer to the link I provided and read up on it.
 
@isTest
private class myClass {
     static testMethod void myTest() {
        FindunpaidInvoices newInst = new FindunpaidInvoices();
      
       List invoice = newInst.getUnpaidInvoces();

      // Add some test code to make sure that invoice is what you are expecting.
    }
}

 
Shivani ThaparShivani Thapar
ok so just to confirm, i add that to my current class, underneath the code I wrote or above it?
jp1234jp1234
That would be a new class, so a new file.