Skip to main content
3 of 4
added 16 characters in body; edited tags
user58
  • 15
  • 1
  • 7

How to insert or escape single quotes at beginning and end of a null value or replace null with single quotes only

I have this method below that Returns a String of Id's separated by '|' operator and it works. However now I would like to add on that if an Id is null or blank replace with just single quotes (''). Not sure how to do that. How can i modify this method to do that.

public static string getString(Set<Id> setId)
       {
           String strId = '';
           if(setId != null && setId.size() > 0 )
           {
                for(Id RecordId :setId)
                {
                    String strRecordId = RecordId;
                    if(strRecordId.length() > 15){
                        strRecordId = strRecordId.substring(0,15);
                    }
                    strRecordId = '\''+ strRecordId + '\'';
                    strId += strRecordId + '|';
                }
                strId = strId.removeEnd('|');
           } 
           return strId;
       }
user58
  • 15
  • 1
  • 7