You need to sign in to do that
Don't have an account?

Trigger: On Oppotunity to create Job object Records
Hi,
Criteria:
On create Opportunity record , the Job Object records will create with according to Opportunity 'Quntity' Field ex: if quntity is 5 then create 5 job records and opportunity 'Amount' set in Job Object divided by 5 ex: If quntity is 5 and Amount is 1000 , set 200 to each Job records
I did this but didn't work
Please answer it.
Thanks in Advance.
Criteria:
On create Opportunity record , the Job Object records will create with according to Opportunity 'Quntity' Field ex: if quntity is 5 then create 5 job records and opportunity 'Amount' set in Job Object divided by 5 ex: If quntity is 5 and Amount is 1000 , set 200 to each Job records
I did this but didn't work
Please answer it.
Thanks in Advance.
If(Trigger.IsAfter && Trigger.isInsert) { for(Opportunity opp : Trigger.New) { Decimal Amount = opp.Amount / opp.TotalOpportunityQuantity; List<job__c> listofjob = new List<job__c>(); for(integer i = 1; i<=opp.TotalOpportunityQuantity; i++) { job__c ajob = new job__c(Name = 'Job'+i, Amount__c =Amount ); listofjob.add(ajob); } if(listofjob.size()>0) { insert listofjob; } } }
Please refer the below code. The trigger will execute only when the new Opportunity will create. It won't execute on the update of the opportunity.
Hope this will help you. If does than mark it as the best answer so it can also help others in the future.
Many Thanks,
Sunil Rathore
All Answers
Your code looks perfect. You just need to avoid performing DML operation inside the for loop. I have removed the Insert Operation from the for loop.
While insertion of the Job record make sure that value should be assigned to all the required field of the Job and hoping that your trigger is Active.
Refer to the below-updated code.
Hope this will help you. If does than mark it as the best answer so it can also help others in the future.
Many Thanks,
Sunil Rathore
I created master detailed field related to Opportunity in Job Object.
Trigger is also active.
and call all requried field.
There is a governor limit for DML statements. To avoid hitting the governor limit it is a best practice to avoid writing DML statements inside the for loop. It won't affect the signal record but when you perform an operation on bulk record it will throw an error.
Please refer the below link for all salesforce governor limits:
https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htm
Hope this will help you.
Many Thanks,
Sunil Rathore
Please refer the below code. The trigger will execute only when the new Opportunity will create. It won't execute on the update of the opportunity.
Hope this will help you. If does than mark it as the best answer so it can also help others in the future.
Many Thanks,
Sunil Rathore
i use this code but it didn't work