You need to sign in to do that
Don't have an account?
Alexa Kaiser
Having trouble with my Test Class on Auto-Opp creating trigger
Hi,
First bear with me, I'm an admin learning Apex.
I created a trigger that creates an Opportunity once an Account is created, it's working great but im struggling with the test class.
I realize I have an issues with line 5, but im unsure how to insert the date fields into the test account that will then pull through to the new test opportunity (I tried to remove them and got an error that Variable did not exist).
Thoughts? Help?
First bear with me, I'm an admin learning Apex.
I created a trigger that creates an Opportunity once an Account is created, it's working great but im struggling with the test class.
I realize I have an issues with line 5, but im unsure how to insert the date fields into the test account that will then pull through to the new test opportunity (I tried to remove them and got an error that Variable did not exist).
Thoughts? Help?
Change your 2 lines of code in your Test class. the date format which you assigned is not correct @ line 5,6.
If your Field is Date DataType
Or IF your Field is DateTime DataType
its should work.
Mark Best ANSWER if its works for you.
Thanks
karthik
All Answers
1) a trick for indenting your code easily: select all your code (CTRL + A) and fix the indentation (Edit > Fix Indentation ( SHIFT + TAB ))
2) post your code here with the button "< >" (Add a code sample) so other people can copy/paste it.
3) a date is created like that in Apex: Date myDate = Date.newInstance(2016, 1, 20) (or Date myDate = Date.today(); )
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_date.htm
Alain
Change your 2 lines of code in your Test class. the date format which you assigned is not correct @ line 5,6.
If your Field is Date DataType
Or IF your Field is DateTime DataType
its should work.
Mark Best ANSWER if its works for you.
Thanks
karthik
My concern is the trigger works with the date mapping I added but will the test class cause any issues?
Test clas
Trigger
If you got 100 % code coverage then no issues in your test class. Go head and deply your code in to production. it will work if your logic is perfectly correct.
Hope this will help you.
Thanks
karthik
You have to verify if these values also exist in production.
opp.RecordTypeId = '0121a0000001nPRAAY';
opp.OwnerId = '0051a000001jvogAAA';
Beautifying your code : select all your code (CTRL + A) and fix the indentation (Edit > Fix Indentation ( SHIFT + TAB ))
File headers should include (comments) /* */
– Description of purpose.
– Names / emails of the author
– Date of creation, and last modification.
– Related metadata (eg. classes, triggers, objects, VF pages).
Regards
Alain