function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Prateek GargPrateek Garg 

in line 12 it is showing error.....([object Object]: invalid cross reference id) please help me to get rid of it.

trigger stockupdate on Line_Item2__c (before insert,before update) {
List<Stock__c> sto= new List<Stock__c>();
    if(trigger.isinsert){
for(Line_Item2__c li:trigger.new){
sto.add(new Stock__c(Name=li.Product_Code__c,Product_Name__c=li.Product_Name__c,Manufacturing_Date__c=li.Manufacturing_Date__c,Batch_No__c=li.name,Expiry_Date__c=li.Expiry_Date__c,No_Of_Boxes__c=li.No_Of_Boxes__c,Pieces_Per_Box__c=li.Pieces_Per_Box__c,Manufacturer_Name__c=li.Manufacturer_Name__c,Total_No_Of_Pieces__c=li.Total_No_Of_Pieces__c)) ;           
                                  }
        insert sto;  
    }
     if(trigger.isupdate){
        for(Line_Item2__c lt:trigger.new){
            stock__c st;  
            st.Name=lt.Product_Code__c;
            st.Product_Name__c=lt.Product_Name__c;
            st.Manufacturing_Date__c=lt.Manufacturing_Date__c;
            st.Batch_No__c=lt.name;
            st.Expiry_Date__c=lt.Expiry_Date__c;
            st.No_Of_Boxes__c=lt.No_Of_Boxes__c;
            st.Pieces_Per_Box__c=lt.Pieces_Per_Box__c;
            st.Manufacturer_Name__c=lt.Manufacturer_Name__c;
            st.Total_No_Of_Pieces__c=lt.Total_No_Of_Pieces__c;
            sto.add(st);
            
            
        }
   upsert sto;
     }
}

Thanks in advance
Tavva Sai KrishnaTavva Sai Krishna
Hi Garg,

The error is that you are assigning the wrong lookup id. (Eg. your are trying to give the AccountId for the contact lookup field). so re-check the look up record id that you are assigning to the field.

Please let me know still if you have any issues. 

Thanks and Regards,
Sai Krishna Tavva.
Prateek GargPrateek Garg
Tavva Sai Krishna Thanks for your Help.The problem is  their is no relationship between these objects.So their is no lookup.what i am doing is i am trying to create a record in lineitem object and when its get created a same record is created in my stock object.but these objects are not related.