function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
wt35wt35 

String concatenation issue in before udpate trigger: concatenates twice

Hi all,

I am facing an issue in a before update trigger, I am just trying to add some characters at the end of a String field:

Trigger.new[0].myField__c  =  Trigger.new[0].myField__c  +  ',00' ;

The issue is that when I enter 12 in this field I should get 12,00.
However I get : 12,00,00

So it looks like my string is concatenated twice...could someone help?

Thanks!
Best Answer chosen by wt35
DevADSDevADS
Hey,

May be your trigger excuting recursively. Can you please share your code, so that we can analyse. 

Thanks!

All Answers

DevADSDevADS
Hey,

May be your trigger excuting recursively. Can you please share your code, so that we can analyse. 

Thanks!
This was selected as the best answer
wt35wt35
Sure, here it is (that is what I am thinking about as well):

trigger CountryFieldFormatting on Personal_Data__c (before insert,before update) {
   
   
    Map<Integer, String> monthMap = new Map<Integer, String>();
    monthMap.put(1,  'January');                
    monthMap.put(2,  'February');              
    monthMap.put(3,  'March');                
    monthMap.put(4,  'April');                       
    monthMap.put(5,  'May');                
    monthMap.put(6,  'June');               
    monthMap.put(7,  'July');                
    monthMap.put(8,  'August');               
    monthMap.put(9,  'September');           
    monthMap.put(10, 'October');              
    monthMap.put(11, 'November');                
    monthMap.put(12, 'December');  
   
       
       
    public String formatDateToLocalDate(Date d){
        if(d == null) return null;
        String localDate;
        String month = getLocalMonthName (  monthMap.get(d.Month())   ,   mt   )  ;
        if (dnf.Starts_with_Month_or_Day__c == 'Day' )   localDate = d.Day() + ' ' + month  + ' ' + d.Year(); 
        if (dnf.Starts_with_Month_or_Day__c == 'Month' ) localDate = month   + ' ' + d.Day()+ ', ' + d.Year();      
        return localDate;
    }
                     
    public String formatCurrencyToLocalCurrency(String amount){
        String s;
        s = amount + decimalSeparator + '00';
        return s;
    }      
   
    public String getLocalMonthName(String month, Months_Translations__c mt){
        Map<String, Schema.SObjectField> mtMap = Schema.SObjectType.Months_Translations__c.fields.getMap();
        String localMonthName = (String) mt.get(mtMap.get(month+'__c'));
        return localMonthName;
    }
   
   
    String s;
    if(Trigger.new[0].SAP_Proposed_Country__c != null) s = Trigger.new[0].SAP_Proposed_Country__c;
    else if (Trigger.new[0].SAP_Home_Country__c != null) s = Trigger.new[0].SAP_Home_Country__c;
    Date_Number_Formats__c dnf = Date_Number_Formats__c.getInstance(s);
    String language = dnf.Language__c;
    Months_Translations__c mt = Months_Translations__c.getInstance(language);
    String decimalSeparator = dnf.Decimal_Separator__c;
    String thousandsSeparator = dnf.Thousands_Separator__c;
    
 
    String temp = '';
    temp = String.valueOf(Trigger.new[0].Base_Pay__c);
    Trigger.new[0].Base_Pay__c = temp  + (decimalSeparator + '00');
   
     
}
wt35wt35
You were right, trigger was recursive, that is fixed now