You need to sign in to do that
Don't have an account?
Creating unique integer id from SF account id
Hi to all,
I am working on a project that I have to crate a unique id ..integer.. by converting salesforce id from alphanumeric to integer every time a new account is saved or updated-and-field-is-empty. I have written a trigger creating that field by removing letters from salesforce id but I receive a read only error when I try to update account record (after insert, after update). If I use it before insert, before update then salesforce id hasn't been created yet. How do I handle this? Ideas? PS. quite new to Apex ...
I am working on a project that I have to crate a unique id ..integer.. by converting salesforce id from alphanumeric to integer every time a new account is saved or updated-and-field-is-empty. I have written a trigger creating that field by removing letters from salesforce id but I receive a read only error when I try to update account record (after insert, after update). If I use it before insert, before update then salesforce id hasn't been created yet. How do I handle this? Ideas? PS. quite new to Apex ...
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm
In winter 15 release there is "Submit and Monitor Jobs for Asynchronous Execution with the Queueable Interface" that will be an alternative to future methods for this sort of problem.
All Answers
If you want to use a trigger - you will need to create a copy of the object and then call update. For an example, look at this thread
-
http://salesforce.stackexchange.com/questions/23891/need-a-update-trigger-to-fire-after-record-insert
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UniqueID: execution of AfterInsert
caused by: System.FinalException: Record is read-only
On another note, how is it possible to turn clear alphanumeric from letters and convert it to numeric with field update?
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm
In winter 15 release there is "Submit and Monitor Jobs for Asynchronous Execution with the Queueable Interface" that will be an alternative to future methods for this sort of problem.
The object ids in salesforce is a string. Each character in the id can be a 0-9 number or upper/lower case character (although you can ignore first three characters since they identify the record's object type). So I am not sure how you will convert them to numbers. My reply was more about trying to get around the problem you had with the trigger update.
If you need a numeric id on each record of an object, I would say add an auto number field to the object.
AK: I thought of that earlier. I will see if I can use something like that.
Shashikant: you gave me good idea .. I already researched about future methods and will try them just to add to my experience.