Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

In the string class apex, what does the .substring function do?

Asked by Buffy Heaton Apr 17, 2023 2.7K views 1 answer
Share

About this question

See I'm getting this field from an integration with wookie, and the field should go to Salesforce in currency format. I get it with the following value: BRL 20.000,00 (Twenty thousand reais)I need to treat this value, removing the letters, removing the "." and replacing the "," with "." The final result should be a decimal 20000.00 So far I'm:

//With this line I get the result I want
acc.Capital_Social__c= Decimal.valueOf((String.valueOf(results.get('capital_social')).replaceAll('[^0-9,]', '')).replace(',', '.'));
The problem is that before I implemented this solution, this was the code used:
acc.Capital_Social__c = Decimal.valueOf(String.valueOf(results.get('capital_social')).substring(3).remove('.').replace(',', '.'));
You will notice that I stopped using the function

.substring(3)

acc.Capital_Social__c= Decimal.valueOf((String.valueOf(results.get('capital_social')).replaceAll('[^0-9,.]', '')).substring(3).remove('. ').replace(',', '.'));

Because when I put it the result generated is: 0.00

I don't understand why I get this result. I don't understand what this ".substring(3)" function was doing in the old code, on google I didn't enter an explanation about this function. I'm afraid that she will be missed at some point. I would like to know if anyone knows this function, if they understand its purpose, if it is really needed, and why it is returning 0.00

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.