How to use Apex for text automation