You need to sign in to do that
Don't have an account?
Norm Copeland
Creating a Test Class - help needed
Hi, I'm a relatively new Salesforce admin (~ 1 yr) and this past weekend set up my first apex trigger that batch creates and emails them using the SDocs app.
It works perfectly in my sandbox and I'm excited to use it in production however I'm struggling to set up and run the required test class before I deploy it. I've looked up Salesforce documentation related to creating Test Classes but haven't had any luck. Would anyone be able to help me create a test class for this apex trigger? I'd really appreciate it! Thanks in advance..
Here's the code for my apex trigger:
It works perfectly in my sandbox and I'm excited to use it in production however I'm struggling to set up and run the required test class before I deploy it. I've looked up Salesforce documentation related to creating Test Classes but haven't had any luck. Would anyone be able to help me create a test class for this apex trigger? I'd really appreciate it! Thanks in advance..
Here's the code for my apex trigger:
trigger SDocsSendForumReminder on Program_Application__c (before update) { for (Program_Application__c l : Trigger.new) if (l.SDocs_Send_Forum_Reminder__c){ SDOC.SDBatch.CreateSDoc(UserInfo.getSessionId(),'id='+l.id+'&Object=Program_Application__c&doclist=a1d170000000G1B&oneclick=1&sendEmail=1'); l.Sdocs_Forum_Reminder_Send_Time__c= datetime.now(); l.SDocs_Send_Forum_Reminder__c=false; }}
Please try below code :-
NOTE: This code has not been tested and may contain typographical or logical errors
NOTE:- Always follow below best pratice for test classes.
1) Make calls to methods using both valid and invalid inputs.
2) Complete successfully without throwing any exceptions, unless those errors are expected and caught in a try…catch block.
3) Always handle all exceptions that are caught, instead of merely catching the exceptions.
4) Use System.assert methods to prove that code behaves properly.
5) Use the runAs method to test your application in different user contexts.
6) Exercise bulk trigger functionality—use at least 20 records in your tests.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
All Answers
Please try with below code and add mandatory fields to program application .
Thnaks
Manoj
Please try below code :- NOTE: This code has not been tested and may contain typographical or logical errors
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
You need to create program__c and Contact record and add id to the lookup filed .
Incase any other lookup field which is mandatory in program and contact then you need to add and asign id .
Let us know any issue .
Please try below code :- NOTE: This code has not been tested and may contain typographical or logical errors
NOTE:- Always follow below best pratice for test classes.
1) Make calls to methods using both valid and invalid inputs.
2) Complete successfully without throwing any exceptions, unless those errors are expected and caught in a try…catch block.
3) Always handle all exceptions that are caught, instead of merely catching the exceptions.
4) Use System.assert methods to prove that code behaves properly.
5) Use the runAs method to test your application in different user contexts.
6) Exercise bulk trigger functionality—use at least 20 records in your tests.
Please refer below link for test classes :-
https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
http://blog.shivanathd.com/2013/11/Best-Practices-Test-Class-in-Salesforce.html
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
I'm getting the following compile error:
Method does not exist or incorrect signature: System.assertEqual(Boolean, Boolean) at line 34 column 12
Amit, do you have any idea what's wrong with this line?
Thanks again, much appreciated.
You are missing a s in your method name .Try with below it wil help !
System.assertEquals( prgapp.SDocs_Send_Forum_Reminder__c,true);
Thanks
Manoj
Please try below code :-
NOTE: This code has not been tested and may contain typographical or logical errors
NOTE:- Always follow below best pratice for test classes.
1) Make calls to methods using both valid and invalid inputs.
2) Complete successfully without throwing any exceptions, unless those errors are expected and caught in a try…catch block.
3) Always handle all exceptions that are caught, instead of merely catching the exceptions.
4) Use System.assert methods to prove that code behaves properly.
5) Use the runAs method to test your application in different user contexts.
6) Exercise bulk trigger functionality—use at least 20 records in your tests.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
Thanks everyone for the help, this was a great learning experience for me. I have a much better understanding of test classes and how they're structured.
Appreciate the help of the community.
International wire transfer is one of the fastest manner to get hold of money from foreign countries. Banks use SWIFT community for changing messages required for performing international wire switch. click for info Usually, the receiving bank (in USA) and the sending financial institution (in different u . S . A .) want to have a right away association in region to start the fast transfer – this is every now and then known as correspondent banking.