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
nksfnksf 

Cross Object Field Update without relationship

Hi Guys can you please help me out with this Trigger? We are using Managed Package and I am not able to update any Trigger in Managed Package.
We have Order custom object and whenever we update status of Order to Released then Invoice gets generated. We don't have any relationship between Order and Invoice Object. It is happening through the managed package. 
I need couple of Order Fields Values copy over to Invoice when the new invoice gets generated. 
Order Fields: Cancel Reason and Credit Reason     Invoice Fields: Cancel Reason and Credit Reason
So when Invoice gets generated it should copy Order Cancel and Credit Reason over to Invoice Cancel and Credit Reason

Any idea how it can be achieved?
Best Answer chosen by nksf
Shashikant SharmaShashikant Sharma
Yes there could be a Junction Object, try to find a object which has reference to Both Order and Invoice. Although it is difficult to say any thing about your object model.

All Answers

Shashikant SharmaShashikant Sharma
You would have to write a custom trigger for this on after update of Order . But I will suggest you more details once you tell me about

Thanks
Shashikant
nksfnksf
I only need to populate couple of Order object fields to Invoice Object when the new Invoice gets generated of the Order. So if on Order page Cancel Reason = xyz then we have same field on Invoice Object as Cancel Reason and Cancel Reason on Invoice page should also be = xyz once this Invoice gets generated. But we don't have any relationship between Order Object and Invoice Object. 
Shashikant SharmaShashikant Sharma
There has to be some logic to find appropriate invoice for the order. If not a reference then some field values from invoice which are same on Order will determine. 

So what you could do is to write a trigger on Invoice before insert and based on some criteria find the appropriate order and fetch the fields that you want.
nksfnksf
Thats the problem we have managed package and I can't see that how they are generating invoice once we update status on Order Object to Released. Since there is no direct relationship between Order and Invoice Objects do you think there could be junction Object which I can use for this Trigger? On Order Page I also see related list as Related Invoices, which shows all the related invoices of the Order. 
Shashikant SharmaShashikant Sharma
Yes there could be a Junction Object, try to find a object which has reference to Both Order and Invoice. Although it is difficult to say any thing about your object model.
This was selected as the best answer
nksfnksf
Hi Shashikant,
Yes I found a Junction Object and I don't need Trigger for this anymore. It can be done by Process Builder. Thanks for your help.