top of page
Writer's pictureAmol Wagh

How to Extract Integer value from String using trigger.

Updated: Mar 1, 2023


To extract the Integer value from the the text field, we can use trigger and populate the number field with the extracted Integer value, below are the steps for that.


1) Create a number field to populate the result into that. In my case, I named it as "Extracted Number" with API name "Extracted_Number__c" on account object.

You can make field read only if you want. It wont affect the result as we are going to edit it in the trigger. :-)



Details about the number field on account object
Extracted Number Field

2) Go to Developer Console and create the new trigger which will execute when new record is created and every time its edited.

For detailed information on Pattern class in apex click here.


3) Here we are fetching the string from field "Account Number" and by matching it with the pattern, we are extracting the number from String.


4) Once we save the trigger, we will get the result as we had planned at the starting.


Below you can see working as expected.

Hooray, we did it !

Yorumlar


bottom of page