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

How to insert values from one custom object to another custom object
Hi Folks,
I have crated 2 custom objects: AR__c and Opportunity_Invoice__c
Now i nvoked a trigger on a AR__c object so once i save any record in AR_c object the trigger should fire and create a new record in Opportunity_Invoice__c object .
my code is follows:
trigger:
*** Beginning Test 1: OpportunityInvoice.public static testMethod void testIcreateOppInvoice()
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 17, column 9: 1
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 19, column 9: date:2008-05-28 00:00:00
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 21, column 9: Invoice descriptionFirst Invoice Line Desc
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 26, column 9: Name:Best Invoice
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 27, column 9: oppInvoice:(Opportunity_Invoice__c:{Date__c=Wed May 28 00:00:00 GMT 2008, Line_Description__c=First Invoice Line Desc, Name=Best Invoice})
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 28, column 9: Insert: LIST:SOBJECT:Opportunity_Invoice__c
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 28, column 9: DML Operation executed in 26 ms
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 29, column 9: Inserted:
20080529040720.360:Class.OpportunityInvoice: line 12, column 35: returning from end of method public static testMethod void testIcreateOppInvoice() in 28 ms
Cumulative resource usage:
Resource usage for namespace: (default)
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 500
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 100
Number of DML rows: 1 out of 500
Number of script statements: 14 out of 200000
Maximum heap size: 0 out of 500000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Total email recipients queued to be sent : 0
*** Ending Test OpportunityInvoice.public static testMethod void testIcreateOppInvoice()
I have crated 2 custom objects: AR__c and Opportunity_Invoice__c
Now i nvoked a trigger on a AR__c object so once i save any record in AR_c object the trigger should fire and create a new record in Opportunity_Invoice__c object .
my code is follows:
trigger:
trigger ARPTrigger on AR__c (before insert) {
for(AR__c arpc : Trigger.new){
String text=' Invoice';
OpportunityInvoice.createOppInvoice(arpc.Invoice_Scheduling_Date__c,arpc.Invoice_Line_Description__c,arpc.Name+text);
}
}
and my class is follows:
public class OpportunityInvoice{
public static void createOppInvoice(Date invoiceDate,String invoiceLineDesc,String Name){
Opportunity_Invoice__c record= new Opportunity_Invoice__c();
record.Date__c=invoiceDate;
record.Line_Description__c=invoiceLineDesc;
record.Name=Name;
Opportunity_Invoice__c[] oppInvoice = new Opportunity_Invoice__c[]{record};
// Attempt to insert it...
insert oppInvoice ;
}
}
compilation successful(Tested this using test methodsee the log )
Debug Log
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 17, column 9: 1
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 19, column 9: date:2008-05-28 00:00:00
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 21, column 9: Invoice descriptionFirst Invoice Line Desc
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 26, column 9: Name:Best Invoice
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 27, column 9: oppInvoice:(Opportunity_Invoice__c:{Date__c=Wed May 28 00:00:00 GMT 2008, Line_Description__c=First Invoice Line Desc, Name=Best Invoice})
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 28, column 9: Insert: LIST:SOBJECT:Opportunity_Invoice__c
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 28, column 9: DML Operation executed in 26 ms
20080529040720.360:Class.OpportunityInvoice.testIcreateOppInvoice: line 29, column 9: Inserted:
20080529040720.360:Class.OpportunityInvoice: line 12, column 35: returning from end of method public static testMethod void testIcreateOppInvoice() in 28 ms
Cumulative resource usage:
Resource usage for namespace: (default)
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 500
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 100
Number of DML rows: 1 out of 500
Number of script statements: 14 out of 200000
Maximum heap size: 0 out of 500000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Total email recipients queued to be sent : 0
*** Ending Test OpportunityInvoice.public static testMethod void testIcreateOppInvoice()
but when i crate a record in custom object the trigger should fire and call the class
and insert record in to Opportunity_Invoice__c object but no record is inserted in to Opportunity_Invoice__c object
when i created a record in AR__c object, can u suggest me , how can make this successful.
Regards,
Rajeshwar.

try in after insert trigger.

Still after insert does n't work.

The code looks ok. Assuming you are on the sandbox - Is the trigger active on the custom object AR__c?

iam working on developer edition and trigger invoked on AR__c object.