+ Start a Discussion
Derek Patrick DayaDerek Patrick Daya 

Invalid id: Error is in expression '{!processSelected}' in component <apex:commandButton> in page ddmasssms: External entry point

Hello Everyone,

I need your assistance to an issue I am facing right now. I've created a VF page that allows users to send an SMS message to Campaign Members. The page has a function that allows users to select a template to use and it's working very well! Unfortunately when the users did not select a template and decided to just type in the message they get the error (Invalid id: Error is in expression '{!processSelected}' in component <apex:commandButton> in page ddmasssms: External entry point). I've looked into it and most of the information available pertains to not "!=" so I changed all <> to != but still receive the same error.

Here is the code to display the list of templates:-

public List<SelectOption> getListOftemplates(){
           List<SelectOption> TemplateOptionList = new List<SelectOption>();
           TemplateOptionList .add(new SelectOption( ' ' ,'--Select--'));
           for(SMS_Data_Template__c sdl: templatemap.values())
                      TemplateOptionList .add(new SelectOption(sdl.id , sdl.Name));
          return TemplateOptionList ;
    public pagereference gettemplate(){
          sdl = [select id,Text_Message__c from SMS_Data_Template__c where id=:selectedtemplateId];
          return null;


Here is the code to place the message on the VF page:

public void updatemessage(){
        sd2.Text_Message__c = templatemap.get(selectedtemplateId).Text_Message__c;

Here is the code to replace the merge fields with correct values:-

if(templatemap.get(selectedtemplateId) != null) {
                            sd.Text_Message__c = templatemap.get(selectedtemplateId).Text_Message__c.replace('{!FirstName}', cm.Firstname==null?'':cm.Firstname).replace('{!LastName}',  cm.Lastname==null?'':cm.Lastname).replace('{!SMS_Mobile_Number__c}', cm.SMS_Mobile_Number__c==null?'':cm.SMS_Mobile_Number__c).replace('{!email}', cm.email==null?'':cm.email);
                            sd2.Text_Message__c = templatemap.get(selectedtemplateId).Text_Message__c.replace('{!FirstName}', cm.Firstname==null?'':cm.Firstname).replace('{!LastName}', cm.Lastname==null?'':cm.Lastname).replace('{!SMS_Mobile_Number__c}', cm.SMS_Mobile_Number__c==null?'':cm.SMS_Mobile_Number__c).replace('{!email}', cm.email==null?'':cm.email);
                        } else {
                        sd.Text_Message__c = sd2.Text_Message__c;

Thank you so much in advance for your help.

Derek Patrick DayaDerek Patrick Daya

After further checking, I've found out that the it's not able to identify that the MAP is null. It is looking for the Id of the template selected even though that field is left blank.

if(templatemap.get(selectedtemplateId).Text_Message__c != null) {
                            sd.Text_Message__c = templatemap.get(selectedtemplateId).Text_Message__c.replace('{!FirstName}', cm.Firstname==null?'':cm.Firstname).replace('{!LastName}',  cm.Lastname==null?'':cm.Lastname).replace('{!SMS_Mobile_Number__c}', cm.SMS_Mobile_Number__c==null?'':cm.SMS_Mobile_Number__c).replace('{!email}', cm.email==null?'':cm.email);
                            sd2.Text_Message__c = templatemap.get(selectedtemplateId).Text_Message__c.replace('{!FirstName}', cm.Firstname==null?'':cm.Firstname).replace('{!LastName}', cm.Lastname==null?'':cm.Lastname).replace('{!SMS_Mobile_Number__c}', cm.SMS_Mobile_Number__c==null?'':cm.SMS_Mobile_Number__c).replace('{!email}', cm.email==null?'':cm.email);
                        } else {
                        sd.Text_Message__c = sd2.Text_Message__c;

I've tried to add/use if(templatemap.ContainsKey(selectedtemplateId)){} but it still failed to know that the selectedtemplateId is NULL.