You need to sign in to do that
Don't have an account?
AlecS
Create multiple custom object using trigger
Here's my scenario.
I have a custome object called Invoice__c.
When my Contract is activated, I want to create as many Invoice__c objects as there are years in the contract. That is, if I have a 3 year contract, then I should create 3 Invoice__c objects after Contract is activated.
How can I do that?
I am able to create one intance of the Invoice__c object. I am having issues creating multiple objects.
Thanks a lot!
You can use the following code to start off.
I have written a crude version for inserts. You will probably need to add logic for updates as well.
@Anwar - I dont mean to discourage you, but you should improve your code quality. I can see that you have nested loops, SOQL inside loops and DML inside loops. These are just invitations to hit the governor limits.
All Answers
Have you tried passing a list of Invoice__c?
Not sure if that works, but just a suggestion.
Hi AlecS,
I think this will help to you.
Here When i create enquiry ,that time automatically create contact.
use this code and modify enquiry with contact and contact with invoice object
Trigger Autocreateenquirycontacts1 on Enquiry__c (After update)
{
Set<string> st = new set<string>();
List<Contact> dlist1 = new List<Contact>();
List<Enquiry__c> pid = Trigger.new;
for (Enquiry__c i:pid)
st.add(i.id);
for (string s:st)
for (Enquiry__c apt:Trigger.New )
IF(apt.Rcd_Type_Name__c=='Qualified Enquiry')
{
for (Enquiry__c pmst : [SELECT id,Enquiry_Name__c, First_Name__c,Last_Name__c, FROM Enquiry__c Where id=:s ])
{ dlist1.add(new Contact(
Enquiry_Name__c =pmst.Enquiry_Name__c,
FirstName= pmst.First_Name__c,
LastName = pmst.Last_Name__c,));
} insert dlist1;
}
}
Thanks
ANWAR
You can use the following code to start off.
I have written a crude version for inserts. You will probably need to add logic for updates as well.
@Anwar - I dont mean to discourage you, but you should improve your code quality. I can see that you have nested loops, SOQL inside loops and DML inside loops. These are just invitations to hit the governor limits.
Jerun,
You are a class apart!!!
Your code worked like a charm!
Thanks much.
-Alec
to make my self clear, i ave a junction object betwen Contact and Event__c, and i need to invite many contacts to an Event using the JunctionObject of course,
any help would be great, Thankx :)