14

I have a trigger where i am assigning ID to a cusotm field like below -

D.customfield__c = acc.Id;

The ID is coming as 00P28000000EwpjEA0

But i need only 00P28000000Ewpj 15 char. Is there is a way to use substring in apex trigger. I can't use formula field.

19

All you need to do is convert the Id to a String and you can call substring(startIndex, endIndex) on it.

The following should work:

D.customfield__c = String.valueOf(acc.Id).substring(0, 15);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.