Activity › Forums › Salesforce® Discussions › How do you perform unit test on a Salesforce trigger?
Tagged: Methods in Salesforce, Required Fields, Salesforce Fields, Salesforce Objects, Salesforce Trigger, Unit Testing
-
How do you perform unit test on a Salesforce trigger?
Posted by Prachi on July 20, 2018 at 10:56 AMHow do you unit test a trigger when you don’t know the required fields?
shariq replied 7 years, 7 months ago 4 Members · 3 Replies -
3 Replies
-
Hi Prachi,
By using the description methods in salesforce you should be able to determine what the required fields are dynamically. But in my suggestion, you must check the required field before implementing the unit test on a particular Object.
Thanks.
- [adinserter block='9']
-
Hi,
Unit tests are class methods that verify whether a particular piece of code is working properly. Unit test methods take no arguments, commit no data to the database, send no emails, and are flagged with the testMethod keyword or the @isTest annotation in the method definition. Also, test methods must be defined in test classes, that is, classes annotated with @isTest.
For example:
@isTest
private class myClass {
static testMethod void myTest() {
// code_block
}
}Thanks
-
Hi,
I think you need to use schema class to get all fields and fill those values and then insert in your test class.
Hope this helps.
Log In to reply.