1
trigger CapitalizeName on Contact( before insert , before update)
{
    for(Contact c : Trigger.new)
        {
            if(c.FirstName != null){

                c.FirstName = c.FirstName.subString(0 ,1).ToUpperCase() +  c.FirstName.subString(1);
                c.LastName =  c.LastName.subString(0 ,1).ToUpperCase() +  c.LastName.subString(1);

                }  
        }
}

I keep getting error with this very basic trigger and I don't understand why, help?

  • Did you copy-paste this trigger from elsewhere? Try typing it out yourself. Seems like it might be a hidden character. – Adrian Larson Mar 9 '17 at 7:33
  • Yes, typed it out in the live code editor it worked. Thanks – Rufus K. Mar 9 '17 at 7:49
1

There's a few zero-width space characters, which was exposed when I copy-pasted this into my notepad program in ANSI mode:

trigger CapitalizeName on Contact( before insert , before update)
{
    for(Contact c : Trigger.new)
        {
            if(c.FirstName ?!= null){

                c.FirstName = c.FirstName.subString(0 ,1).ToUpperCase() +  ?c.FirstName.subString(1);
                c.LastName =  c.LastName.subString(0 ,1).ToUpperCase() +  ?c.LastName.subString(1);

                }  
        }
}

The ? characters are hidden zero-width characters that ended up in your code. Make sure you're not using some sort of fancy editor that likes to insert no-break-spaces or zero-width-spaces.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.