Nothing in Section 5240 shall abrogate or restrict the power of the appropriate court in proper cases to direct or permit a corporation to deviate from the terms of a trust or agreement regarding the making or retention of investments. Notice of such action or proceeding shall be given to the Attorney General who may intervene.