Skip to main content
Dave Walters preguntó en #Apex
When i do a renderEmailTemplate and the template contains:

Dear {!NullValue(Contact.FirstName, "Sir or Madam")} please call

I get an error saying 

Field NullValue(Contact.FirstName, "Sir or Madam") does not exist. Check spelling.

If the template just has {!Contact.FirstName} it works if I select a contact that doesn't have a NULL firstname.  

The NullValue is supposed to fix the situation where there is no data in a certain field.

Here's the code:

body = 'Dear {!NullValue(Contact.FirstName, "Sir or Madam")} please call';

   String[] RenderArr = new String[]{body};

                            

            MergeRes = Messaging.renderEmailTemplate(currentContact.Id,currentContact.Id,RenderArr);

            

            for ( Messaging.RenderEmailTemplateBodyResult mRes : MergeRes){

                if( mRes.getSuccess() == true) {

                    // Do This when it works

                }

                else

                {

                    List<Messaging.RenderEmailTemplateError> Errs = mRes.getErrors();

                    

                    for ( Messaging.RenderEmailTemplateError mErr :  Errs ) {

// Display errors here

                        ShowErrors('Render Err at ' + mErr.getOffset() + ' ' + mErr.getMessage() );

                    }

                }

                    

            }

        }

Does anyone know how to fix this as the NullValue bit i used is exactly what it says to do when you create a tet template.

Thanks

 
3 respuestas
  1. 19 sept 2016, 19:24

    Try this

    {!IF(NOT(ISNULL(Contact.FirstName)),Contact.FirstName,'Sir or Madam')}

0/9000