2018: BADI CRM_BADI_RF_Q1O_SEARCH
A solution to avoid the worst issue into SAP CRM has been created and given to you on our website:
www.sapetabap
forum SAP CRM (you have to subscribe to access to it, free and email not used).
2014: BADI ORDER_SAVE
If you use a SAP CRM solution you have to enhance the standard processes to meet your functionnal processes.
To enhance them you will use BADI.

In Standard ABAP coding way you will create several usage of your badi, 1 for each requirement.
In the previous screenshot we have created 4 BADI usage, 1 for each document type.
Inside 1 of this usage, by example for LEAD document, inside method CHECK_BEFORE_SAVE, you will call CRM_ORDER_READ function module to allow to know which document is currently checked.