+ Start a Discussion

Apex Trigger Help

Hi Friends,

Here is my issue. Please advise me or help me.
I am having a field called Id_Generator__c which is autonumber field under object named custom_account__c. Now I have to write a trigger that will take this autonumber field and encrypt that field and then it has to send that encrypted value to the document I am sending out for signature(esignature) and then after signature the trigger has to get the key and decrypt that and have to store that value. Please let me know if you guys have any idea.


You can use the Crypto class to encrypt or decript. please see the below links:



I am able to write a trigger and generate an encrypted key. Here is the code I used to generate the key. I also created a temporary varaible called Id_Generator_Key__c and store the encrypted value in that key.

rigger EncrypOfAgIdGeneratorTrigger on Custom_Account__c (before insert) {
for (Custom_Account__c ca : Trigger.new) {
DateTime now = System.now();
String formattednow = now.formatGmt('yyyy-MM-dd')+'T'+ now.formatGmt('HH:mm:ss')+'.'+now.formatGMT('SSS')+'Z';
String GeneralId = ca.Id_Generator__c + formattednow;
Blob bsig = Crypto.generateDigest('MD5', Blob.valueOf(GeneralId));
System.debug('Blob value:'+bsig);
ca.Id_Generator_Key__c = EncodingUtil.base64Encode(bsig);
And Now I am passing this key to the URL 'https://cs16.salesforce.com/apex/SignUp?Id=yFjMsJE1MifGnnT6oYKefQ=='
Now I want to write a separate class for decryption and have to call this class once the page loaded and then I have to use the id_Generator__c field for the rest of the code. Can any one help how to write decryption code in separate class and how to call that class after loading my above page. Thanks in advance!