You need to sign in to do that
Don't have an account?
sfadm sfadm
After Update Trigger not updating a record field
I'm using the after update trigger to update the "BillingCity" field in the Account object and make the field in proper case.
And the code in the invoked toTitleCase(billingCity) method:
Please advise an appropriate solution.
trigger on Account (after update) { String billingCity = Account.billingCity; toTitleCase(billingCity); }
And the code in the invoked toTitleCase(billingCity) method:
//converts a given string to Title Case where the //first letter of every word is capitalised and the rest are small public String toTitleCase(String billingCity) { System.debug('billingCity ' + billingCity); String titlePhrase = ''; //a set of words that should always be in lower case when in Title Case Set<String> forceLower = new Set<String>{'of', 'the', 'for', 'and', 'a', 'to', 'at' ,'an', 'but', 'if', 'or', 'nor'}; if(billingCity != null && billingCity.length() > 0){ String[] splitPhrase = billingCity.trim().split(' '); for(integer i = 0; i < splitPhrase.size(); i++){ if(!forceLower.contains(splitPhrase[i].toLowerCase()) || i == 0 || i == (splitPhrase.size()-1) ) { titlePhrase += (splitPhrase[i].substring(0,1).toUpperCase())+(splitPhrase[i].substring(1).toLowerCase())+' '; } else { titlePhrase += splitPhrase[i].toLowerCase()+' '; } } } return titlePhrase.trim(); }In the debug log I can see that the "BillinCity" field is updated with the proper case:
17:00:57:945 USER_DEBUG [40]|DEBUG|billingCity San Marinobut on a record level the field remains with upper case: "SAN MARINO"
Please advise an appropriate solution.
Three major problems with your current trigger
Please mark this answer as correct if it helped you!