You need to sign in to do that
Don't have an account?
Benjy Hunt
Trigger to create multiple Custom object records based on the opportunity quantity
Hi All,
I have been asked to create a trigger that will create records on a custom object when an opportinity is closed won. i can do this without issue, but i am running into a problem when the quantity is greater than 1.
What i need is for it to create 2 records if the opportunity quantity is 2 but i have no idea how to do this.
any help would be greatly appreciated
I have been asked to create a trigger that will create records on a custom object when an opportinity is closed won. i can do this without issue, but i am running into a problem when the quantity is greater than 1.
What i need is for it to create 2 records if the opportunity quantity is 2 but i have no idea how to do this.
any help would be greatly appreciated
Please take a look on the below code. It is just a dummy code, you just need to replace the customObject with your real object name.
Hope this helps you out.
Mark it as best.
Thanks
Naresh.
If you always want 2 records than set exit condition to i<2 in the second classic for loop.
any further idea's?
It is on the opportunity. The field API name is TotalOpportunityQuantity, repalce quantity with this.
* ‘Opportunity’ object don’t have any ‘Quantity’ field on it.
But OpportunityLineItems are those Products which are inside any Opportunity, and we have Quantity field for OpportunityLineItems,
* So, We can write code for Quantity of OpportunityLineItems(Products).
So, I have written code for ‘ Quantity’ of OpportunityLineItems as per your question.
* I have written code for ‘update event',
* Whenever you will update any Opportunity, Trigger will be fired
And as per the Quantity of ‘OpportunityLineItems’ within that ‘Opportunity', Number of Records Will be Created on Your Custom Object.
* And Please Replace ‘My_Custom_Obj__c’ with your ‘custom object's name.
After this, you can use this code completely.
If any doubt, you can ask me.
Hope this may help you.
Regards,
Akshay.