You need to sign in to do that
Don't have an account?
Mathias_K
Need help - testclass
How can i pass a String in a trigger at the testrun?
my testclass :
how can i pass the string and the method??
thx 4 help
trigger tr_EventToReport on Event (after insert, after update) { if (Trigger.isInsert){ for (Event events : Trigger.new) { if (events.Type == 'SD_KeyAccount_Visit'){ // URL auslesen für Ereignisverlinkung String baseUrl = System.URL.getSalesforceBaseUrl().toExternalForm()+'/'+events.Id; createVisitReports cvr = new createVisitReports(); cvr.createVisitReport('0127E0000000pTqQAI', events.AccountId, events.WhoId, baseUrl); } else { System.debug('KEIN KEYACCOUNT BESUCH'); } } } }
my testclass :
@isTest private class test_Create_Event { @isTest public static void createEvent(){ // Erstellen eines Termins für Triggeraktivierung Event ev = new Event(OwnerID = '0057E000002cOCVQA2', Type = 'KeyAccount Besuch', ActivityDateTime = Date.valueOf('2017-07-12 12:30:00') , EndDateTime = Date.valueOf('2017-07-12 13:30:00'), WhoID = '0037E00000TAqP8QAL'); insert ev; // Perform test Test.startTest(); Database.DeleteResult result = Database.delete(ev, false); Test.stopTest(); } }
how can i pass the string and the method??
thx 4 help
I will recommend you to start using trailhead to learn about test classes
1) https://trailhead.salesforce.com/modules/apex_testing
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
You write a test class for this the same way that you would any other:
- Set up some data for the Trigger to access (in this case it looks like Even)
- Instantiate the Trigger- by insert or update
- Execute a method/methods
- Verify the behaviour with asserts.
Please try below code in your code
Let us know if this will help you
All Answers
There are few rules to write trigger:
As I can see above, there is not methods in trigger. Where do you need to send String variable. Please follow above apporach and pass the value from Test class to method.
Hope this helps.
Thanks,
Gaurav
I will recommend you to start using trailhead to learn about test classes
1) https://trailhead.salesforce.com/modules/apex_testing
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
You write a test class for this the same way that you would any other:
- Set up some data for the Trigger to access (in this case it looks like Even)
- Instantiate the Trigger- by insert or update
- Execute a method/methods
- Verify the behaviour with asserts.
Please try below code in your code
Let us know if this will help you