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

Auto Create Record
Hi all,
I have written a Trigger in Opportunity it fires when an opportunity is created automatically a record will be created in another object
Here i want multiple records to be created for one Opportunity
Objects :
Opportunity and
Record
Trigger:
trigger AutoCreateRecord on Opportunity (after insert){ List<Record__c> Records = new List<Record__c>(); for (Opportunity newOpportunity: Trigger.New){ if(newOpportunity.CloseDate!=null && newOpportunity.StageName=='Closed Won'){ Records.add(new Record__c( Name ='1', Opportunity__c = newOpportunity.Id, Amount__c = 12)); } } insert Records; }
Hi Affu....
I think Its possible to multiple records for a opportunity....but this loop won't in that case...we need two for loop for this .
Please let me know if there is concerns in this . . Thanks :)
All Answers
multiple records for one opportunity means what is the base logic to create the number of records for one opportunity?
HI Thanks for the reply,
There is no logic but i want to get multiple records with the same data as the first record has, when an Opportunity is created
lets say in Opportunity we have number field as No_Of_Records once u create an Opportunity enter No_Of_Records as 2 or 3 or4 so on those no of records should be created in that Object(Record) related to that Opportunity. Is it Possible?
Thanku........
Hi,
You can create multiple records. You can access your "No_Of_Records" field on Opportunity and then you can use it in your trigger.
example code:
Hope this solves your problem!!
Hi Affu....
I think Its possible to multiple records for a opportunity....but this loop won't in that case...we need two for loop for this .
Please let me know if there is concerns in this . . Thanks :)
Thanks SFDC_Evolve, for correcting me. Written the code on the fly ;).