You need to sign in to do that
Don't have an account?
JeremyB
Trigger to force an "edit/save" (update) to child records. (oppty --> oppty products)
Problem: 1) Cannot do cross-object workflow
1a) Cannot fire workflow off formula field.
So I need a trigger that will force an "edit/save" (that is, an update with no changes necessary) to opportunity products when a user populates a date field, SO_Opened__c, on the opportunity.
Any help, be it code itself or links to get me further along would be great.
Thanks,
Jeremy
Alright, so, you just need to have another Opp update that doesn't have SO_Opened__c set, that will get you line 9, for line 13 you need to make sure that you have an OpportunityLineItem in your test method that is inserted with OpportunityId equal to the updating Opportunity (sorry if that is confusing, but you'll have to do that in order to hit line 15).
All Answers
Hey Jeremy
Can I ask why you need it to perform this update if nothing is being updated? Seems to be a problem with no actual problematic point.
Paul
good question:
It's to get a workflow fired which has a setting of "Every time record is created/edited."
Why do you need this workflow to fire? Are you implementing a workflow today, and you want all your legacy data to meet the requirements that your workflow are checking for?
If this is the case, you can accomplish what you are trying to do through the Apex Data Loader.
Export all the Opportunitys and/or their Products.
Update all the Opportunitys and/or their Products.
Please let me know if this solves your issue.
nope, doesn't affect legacy records. just this point forward.
The workflow does a field update to a formula date field, "Delivery Date" (Delivery_Date__c), on the opp line item.
But in the calculation for this delivery date, it uses the Sales Order opened date as a reference point. So when the Sales Order Opened date (SO_Opened__c) is populated on the opportunity i want that to trigger an update to the line items to have the delivery date populated (via workflow and field udpate).
My request seems simple enough, right?
Going forward, without worrying about legacy records, when a date field, "SO_Entered__c" is populated on the opportunity, trigger an update to all opp line items -- which causes the workflow field update to fire.
here's me attempting (embarrassing attempt), but hey at least I'm trying.
Try this...
Please let me know if this solves the issue....
I enjoy pints of beer. :)
oh, you are awesome. (and as a diehard hockey fan (sharks), I love all things Canada!)
OK, just trying to polish my test class but only getting 50% coverage right now. I'll keep plugging away, but thanks so much again for the help with the trigger!
Just make sure that the Opportunity you are updating has SO_Entered__c set to something, in your example it hasn`t been so part of the trigger while never get executed.
Don't use existing records in test classes as a bad practice, you'll want to just create all your artificial "test" data within the scope of the testmethod, IE just add Line Items and Product Books to the Oppurtunity oppp.
Otherwise, looks good. Pay it forward Jeremy :)
thanks for the heads up with everything, and I most certainly do try to pay it forward, but mostly just in the Answers community where I belong!
By the way, I made a mistake originally: SO_Entered wasn't the correct field name. It's actually SO_Opened!
And in the test class I do have SO_Opened__c set to today.
Coverage:
Alright, so, you just need to have another Opp update that doesn't have SO_Opened__c set, that will get you line 9, for line 13 you need to make sure that you have an OpportunityLineItem in your test method that is inserted with OpportunityId equal to the updating Opportunity (sorry if that is confusing, but you'll have to do that in order to hit line 15).
you are the man!
With a little help from a friend (Ritesh on the boards), I was able to finish this off nicely.
Here is the final code:
Test Class
Hi All:
Thanks for the code, I have 2 custome objects and the same problem.
In line:
List<Operation__c> theLines = [SELECT Id FROM Operation__c WHERE OpportunityId IN :oppIds];
what should I replace my code with.
In my case, parent Object is: Developments and chils object is: Monitoring
Parent Object field is: Overal Risk and child object risk is: PER
Do I need to mention the name of the Workflow as well?
Do I need to mention the Child object filed name as well?
Regards,
Ben