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
dietcoladietcola 

correcting all caps

Is there any easy way to set some kind of data validation so that fields entered in all caps can be corrected to have only the first letter capitalized?  If this can be done either within a web-to-lead form or when a lead is converted to an account, either would work great.  I haven't found anything yet, though.

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
fdsgkgreamfabofdsgkgreamfabo

What about a workflow updating the field itself with a formula?

uppercase(left(Firstname,1)) & lowercase(right(Firstname,len(Firstname)-1))

All Answers

CaptainObviousCaptainObvious

You may need to adjust the coding based on your use case, but if you go with a standard Salesforce Web-to-Lead form, you could use something like this:

In your input field, add an onblur event:

<input name="first_name" id="first_name" type="text" size="30" maxlength="40" onblur="convertCase(this.value,'first_name');" />

Make sure the text in bold matches! In the <script> tags, add the following javasript function:

 

function convertCase(txt,objId){ //Convert the first letter to Upper case var firstLetter = txt.toUpperCase(); firstLetter = firstLetter.substr(0,1); //Convert the remaining letters to Lower case var remLetters = txt.toLowerCase(); remLetters = remLetters.substr(1); document.getElementById(objId).value = firstLetter + remLetters; }

... if you need to add the same functionality to the another field, just add the same onblur event to the field, but change the id:

 

<input name="last_name" id="last_name" type="text" size="30" maxlength="40" onblur="convertCase(this.value,'last_name');" />

I put this together rather quickly so it may need to be adjusted... hope that helps! :smileywink:

dietcoladietcola

Wow, thank you so much for this!  I have background in coding limited to a couple of classes taken in college, but I think I follow what the function does.  I tried adding it to our code on our Force.com Sites page (which is copy/pasted from the web-to-lead functionality in Salesforce), but it didn't work.  The leads still entered our system just fine, but any leads entered in caps still remained in caps.

 

I'm sure I'm missing something simple--do you spot anything off the bat that's screwy in my code?

 

 

<apex:page >
<head>
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></META>
</head>
<!--
<apex:includeScript value="{!$Resource.prototype}"/>
<apex:includeScript value="{!$Resource.scriptaculous}"/>
<script type="text/JavaScript">
  var txt_id = 1;
  function add_txt( tbl ) {
    var row = $(tbl).insertRow(-1);
        var cell = row.insertCell(0);
        cell.innerHTML = "<div id='txt" + ++txt_id +
        "' style='display: none;'>" +
        '<apex:image url="{!$Resource.hut_med}" width="50" height="50" /> ' +
        '<textarea name="" rows="3" cols="20"></textarea></div>';
    Effect.SlideDown( 'txt' + txt_id );
  }

  function del_txt( tbl ) {
    if ( txt_id == 1 ) {
          return;
        }
    Effect.SlideUp( 'txt' + txt_id--, { afterFinish: function () { $(tbl).deleteRow(-1); } } );
  }          

  function convertCase(txt,objId){
    //Convert the first letter to Upper case
    var firstLetter = txt.toUpperCase();
        firstLetter = firstLetter.substr(0,1);
    //Convert the remaining letters to Lower case
    var remLetters = txt.toLowerCase();
        remLetters = remLetters.substr(1);
    document.getElementById(objId).value = firstLetter + remLetters;
  }

</script>
/-->

  <apex:image url="{!$Resource.bpe_logo}" /><br/>
  <h1>Volunteer Application Form</h1><br/><hr>
 

<form action="https://cs3.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">

  <table id="v_app_form" name="v_app_form">
 
  <input type=hidden name="oid" value="00DQ00000009IMo">
<!--  <input type=hidden name="retURL" value="http://bostonpartners.org/"> //-->
 <input type=hidden name="retURL" value="https://cs3.salesforce.com/apex/ThankYou">

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: These fields are optional debugging elements.  Please uncomment   -->
<!--  these lines if you wish to test in debug mode.                          -->
<!--  <input type="hidden" name="debug" value=1>                              -->
<!--  <input type="hidden" name="debugEmail"                                  -->
<!--  value="simon.chao@fmr.com.alpha">                                       -->
<!--  ----------------------------------------------------------------------  -->
  <tr>
    <td><label for="first_name">First Name</label></td>
    <td><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" onblur="convertCase(this.value,'first_name');" /><br/></td>
  </tr>
  <tr>
    <td><label for="last_name">Last Name</label></td>
    <td><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br/></td>
  </tr>
  <tr>
    <td><label for="email">Email</label></td>
    <td><input  id="email" maxlength="80" name="email" size="20" type="text" /><br/></td>
  </tr>
  <tr>
    <td><label for="company">Company</label></td>
    <td><input  id="company" maxlength="40" name="company" size="20" type="text" /><br/></td>
  </tr>
  <tr>
    <td><label for="city">City</label></td>
    <td><input  id="city" maxlength="40" name="city" size="20" type="text" /><br/></td>
  </tr>
  <tr>
    <td><label for="state">State/Province</label></td>
    <td><input  id="state" maxlength="20" name="state" size="20" type="text" /><br/></td>
  </tr>
  <tr>
    <td><input type="submit" name="submit"></td>
  </tr>
  </table>

<!--
<table id='txts'>
  <tr>
    <td>
    <div>
      <apex:image url="{!$Resource.hut_med}" width="50" height="50" />
      <textarea name="" rows="3" cols="20"></textarea>
    </div>
    </td>
  </tr>
</table>

<input type='button' value="add" onclick="add_txt('txts');" />
<input type='button' value="delete" onclick="del_txt('txts');" />
//-->
 
</form> 


</apex:page>

 

 

Sorry to overwhelm this post with code!  =)  Again, thanks very much for your help.

dietcoladietcola
Ha--and I love that this forum interpreted part of the code as smiley faces.  Nice.
CaptainObviousCaptainObvious

I cant see anything off the bat, but just to make sure, change the onblur event to:

onblur="convertCase(this.value,this.id);"

That should make it more dynamic and allow you to place the function in other fields without modification.

The case correction should be triggered as soon as you click on another field or another area of the page (onblur). So if you enter "FIRSTNAME", tab, "LASTNAME", "FIRSTNAME" will be automatically updated to "Firstname".

If you don't see this happening, there may be an error elsewhere on the page. Try using Firefox with the Firebug plugin to locate the source of the error.

dietcoladietcola

The change to make the function more dynamic didn't do the trick, but I suppose it's proper etiquette to make any function more dynamic anyway.  =)

 

Thank you for your help; I will experiment with Firebug.

fdsgkgreamfabofdsgkgreamfabo

What about a workflow updating the field itself with a formula?

uppercase(left(Firstname,1)) & lowercase(right(Firstname,len(Firstname)-1))

This was selected as the best answer
dietcoladietcola

That is a great idea!  I tried it for the First Name field and had success!!  It's not working for the Last Name for some reason--possibly because that's a required field?  I'm still working on troubleshooting that; let me know if you have any ideas.

 

Thank you!!

dietcoladietcola
The problem I was having with the Last Name field was a dumb mistake on my part--the above solution is now working great!  Thanks again so much for your help.
Dev_PeteDev_Pete

I'm having a similar issue but with states on web-to-lead.  Right now I have a state validation rule that says you have to use a valid state abbreviation on the Lead record.  So when some puts Ca instead of CA, they get an error message.  This was ok internally, but now people are coming to our website and getting flustered.

 

 I changed the rule to allow CA, Ca, ca, or cA.  But I would love it if SFDC could just automatically fix these so no matter what is entered, it changes it to all caps in the lead record.

 

How or where would I do this?

CaptainObviousCaptainObvious

Sounds like you have a text field for State on your web to lead form? Try using a picklist instead:

 

 

    <td>
        <select id="state" name="state">
            <option value="" selected="selected"></option>
            <option value="AL">Alabama</option>
            <option value="AK">Alaska</option>
            <option value="AZ">Arizona</option>
            ...
            <option value=""></option>
            <option value="Alberta">Alberta</option>
            <option value="British Columbia">British Columbia</option>
            ...
        </select>
    </td>

 

 

Dev_PeteDev_Pete

That sounds like a good idea!  Thanks! 

Dev_PeteDev_Pete

Ok, here's another thing that has me stuck that you may be able to help with.  I have a formula field for a specific case type we call implementations.  Those implementations have a certain "Go-Live" date.  So i have this formula that works OK to give me red, green or yellow squares depending on the # days to go-live value. 

 

However, I need the square color to go away and come back with the text value of "UNKNOWN" when that # days to go-live is blank.

 

Currently my formula reads like below, but if the Days_Left_to_Go_Live__c field is blank it's returning a red.  Any suggestions?

 

IF( Days_Left_to_Go_Live__c < 20,
IMAGE("/img/samples/color_red.gif", "red", 30, 30),
IF( Days_Left_to_Go_Live__c > 60,
IMAGE("/img/samples/color_green.gif", "green", 30, 30),
IMAGE("/img/samples/color_yellow.gif", "yellow", 30, 30)

) )

CaptainObviousCaptainObvious

You should probably start a new thread for this question, but the following may help:

 

IF( Days_Left_to_Go_Live__c=0,"UNKNOWN",
    IF( Days_Left_to_Go_Live__c < 20, IMAGE("/img/samples/color_red.gif", "red", 30, 30), 
        IF( Days_Left_to_Go_Live__c > 60, IMAGE("/img/samples/color_green.gif", "green", 30, 30), 
            IMAGE("/img/samples/color_yellow.gif", "yellow", 30, 30) 
	    )
    )
)

This is assuming that null values are treated as zero's...

Which brings up the question- what color do you want your box to be when you actually enter a '0'?

You may have to experiment a bit to get the desired result.

 

Dev_PeteDev_Pete

Well it's a date field so if no one puts anything in there, then it's just blank, not a zero.  What about the isblank or isnull thing.  I'm not sure how to use it but wonder if that might work.  I'll try this.  I guess I could have the square be the same color of the background so it looks blank, or the words UNKNOWN could appear.  But right now blanks are getting a red square and that's not good.

 

Thanks,
Pete

JSchneiderJSchneider
There have been some changes to the language used in the formula field, don't know when they changed but I just used this and here's the formula again.

UPPER( LEFT( First_Name__c , 1) ) & LOWER( RIGHT( First_Name__c , LEN( First_Name__c )-1 ) )