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

Populate Lookup Field
Hi All,
Need assistance on my trigger. I have this trigger that creates 2 Invoice Schedule records (custom object) when a new contract is created. The part that I need help on is linking the 2 Invoice Schedule records into the Contract. I need to populate the Contract lookup field (Contract__c) on the Invoice Schedule record.
Thanks in advance.
trigger Technology_AddInvoiceSchedule on Contract (before insert) {
//When a Lynx or iKM contract are created, insert 2 Invoice Schedule records
List<Invoice_Schedule__c> invschedlist = new List<Invoice_Schedule__c>();
for (Contract cont: Trigger.new){
if(cont.RecordTypeId=='012J00000004xUI'||cont.RecordTypeId=='012J00000004xUJ'){
//Record Types are Technology: Lynx and Technology: iKnowMed.
Invoice_Schedule__c invsched1 = new Invoice_Schedule__c();
invsched1.Name='First Invoice';
invsched1.Invoice_Number__c='TBD';
invsched1.Invoice_Amount__c=0;
invsched1.Opportunity__c=cont.Opportunity__c;
invsched1.RecordTypeId='012J00000004zD9';
Invoice_Schedule__c invsched2 = new Invoice_Schedule__c();
invsched2.Name='Recurring Invoice';
invsched2.Invoice_Number__c='TBD';
invsched2.Invoice_Amount__c=0;
invsched2.Opportunity__c=cont.Opportunity__c;
invsched2.RecordTypeId='012J00000004zD9';
invschedlist.add(invsched1);
invschedlist.add(invsched2);
}
if(invschedlist.size()>0)
insert invschedlist;
}
}
Need assistance on my trigger. I have this trigger that creates 2 Invoice Schedule records (custom object) when a new contract is created. The part that I need help on is linking the 2 Invoice Schedule records into the Contract. I need to populate the Contract lookup field (Contract__c) on the Invoice Schedule record.
Thanks in advance.
trigger Technology_AddInvoiceSchedule on Contract (before insert) {
//When a Lynx or iKM contract are created, insert 2 Invoice Schedule records
List<Invoice_Schedule__c> invschedlist = new List<Invoice_Schedule__c>();
for (Contract cont: Trigger.new){
if(cont.RecordTypeId=='012J00000004xUI'||cont.RecordTypeId=='012J00000004xUJ'){
//Record Types are Technology: Lynx and Technology: iKnowMed.
Invoice_Schedule__c invsched1 = new Invoice_Schedule__c();
invsched1.Name='First Invoice';
invsched1.Invoice_Number__c='TBD';
invsched1.Invoice_Amount__c=0;
invsched1.Opportunity__c=cont.Opportunity__c;
invsched1.RecordTypeId='012J00000004zD9';
Invoice_Schedule__c invsched2 = new Invoice_Schedule__c();
invsched2.Name='Recurring Invoice';
invsched2.Invoice_Number__c='TBD';
invsched2.Invoice_Amount__c=0;
invsched2.Opportunity__c=cont.Opportunity__c;
invsched2.RecordTypeId='012J00000004zD9';
invschedlist.add(invsched1);
invschedlist.add(invsched2);
}
if(invschedlist.size()>0)
insert invschedlist;
}
}
I have taken the liberty of updating and cleaning up your code with this update
NOTE: This code has not been tested and my contain typographical or logical errors
All Answers
I have taken the liberty of updating and cleaning up your code with this update
NOTE: This code has not been tested and my contain typographical or logical errors