You need to sign in to do that
Don't have an account?
Christianralph
Testing Workflow Rules from Apex
We are trying to test Workflow rules from Apex tests. WE ARE NOT INTERESTED IN JUST MEETING CODE COVERAGE but in actually testing the functionality of the rule.
Our Rule: (defined manually from SalesForce builder)
When an Opportunity is created, we create a new Task linking it to that opportunity
Apex test (pseudo code)
create valid opportunity
insert opportunity
get all Tasks
assert that new Task was created. (FAILS)
The rule however works when you manually create the opportunity through SalesForce UI
I would guess this is a timing issue - if the tasks are created by WF, then they probably get created after your SOQL query is executed...
Try using test.starttest() and test.stoptest() around the data creation, and then query for the tasks after the stop test
All Answers
I would guess this is a timing issue - if the tasks are created by WF, then they probably get created after your SOQL query is executed...
Try using test.starttest() and test.stoptest() around the data creation, and then query for the tasks after the stop test
Great thanks!
This appears to work :smileyhappy: