Skip to main content
added 21 characters in body
Source Link
samdev
  • 154
  • 2
  • 10

You can use the join method from String class like below to get the string of ids seperated by '|' operator:

String.join( new List<String>(String.join(new List<id>(setId), ',').split(',')) , '|' ));

EDIT: check for isNotBlank for every entry in the for loop:

Edit 2: Added empty check for setId.

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

You can use the join method from String class like below to get the string of ids seperated by '|' operator:

String.join( new List<String>(String.join(new List<id>(setId), ',').split(',')) , '|' ));

EDIT: check for isNotBlank for every entry in the for loop:

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

You can use the join method from String class like below to get the string of ids seperated by '|' operator:

String.join( new List<String>(String.join(new List<id>(setId), ',').split(',')) , '|' ));

EDIT: check for isNotBlank for every entry in the for loop:

Edit 2: Added empty check for setId.

      public static string getString(Set<Id> setId){
    
    String strId = '';
    if(setId != null && setId.size() > 0 ){
        for(Id RecordId :setId){  
            String strRecordId  ='';
            if(String.isNotBlank(RecordId)){
                strRecordId = RecordId;
                if(strRecordId.length() > 15){
                    strRecordId = strRecordId.substring(0,15);
                    strRecordId = '\''+ strRecordId + '\'';
                    strId += strRecordId + '|';
                }                        
            }
            else{
                strRecordId = '\' \'';
                strId += strRecordId + '|';
            }
        }
    }
    else{
        strId = '\' \'';
    }
    strId = strId.removeEnd('|');
    return strId ;
}
deleted 46 characters in body
Source Link
samdev
  • 154
  • 2
  • 10

You can use the join method from String class like below to get the string of ids seperated by '|' operator:

String.join( new List<String>(String.join(new List<id>(setId), ',').split(',')) , '|' ));

EDIT: you can add the entries to a new list and then join them. Also check for isNotBlank for every entry in the for loop:

       public static string getString(Set<Id> setId){
         
    String strId = '';
            if(setId != null && setId.size() > 0 )
            {
                List<String> finalList= New List<String>();
                for(Id RecordId :setId)
        {   
       {
     String strRecordId  ='';
            if(String.isNotBlank(RecordId)){
                        String strRecordId = RecordId;
                        if(strRecordId.length() > 15){
                            strRecordId = strRecordId.substring(0,15);
                         strRecordId = '\''+ finalList.add(strRecordId);
   + '\'';
                    }strId += strRecordId + '|';
                    
                }    }
                    else{
            }
            finalList.add(''); else{
                 strRecordId = '\' }\'';
                }strId += strRecordId + '|';
            }
        }
    }
 strId   strId = StringstrId.joinremoveEnd(finalList,'|');
             return strId ;
            
        }

You can use the join method from String class like below to get the string of ids seperated by '|' operator:

String.join( new List<String>(String.join(new List<id>(setId), ',').split(',')) , '|' ));

EDIT: you can add the entries to a new list and then join them. Also check for isNotBlank for every entry in the for loop:

     public static string getString(Set<Id> setId){
            String strId = '';
            if(setId != null && setId.size() > 0 )
            {
                List<String> finalList= New List<String>();
                for(Id RecordId :setId)
                {
                    if(String.isNotBlank(RecordId)){
                        String strRecordId = RecordId;
                        if(strRecordId.length() > 15){
                            strRecordId = strRecordId.substring(0,15);
                            finalList.add(strRecordId);
                        }                        
                    }
                    else{
                        finalList.add(''); 
                    }
                }
            }
             strId  = String.join(finalList,'|');
             return strId ;
            
        }

You can use the join method from String class like below to get the string of ids seperated by '|' operator:

String.join( new List<String>(String.join(new List<id>(setId), ',').split(',')) , '|' ));

EDIT: check for isNotBlank for every entry in the for loop:

       public static string getString(Set<Id> setId){
     
    String strId = '';
    if(setId != null && setId.size() > 0 )
    {
        
        for(Id RecordId :setId)
        {   
            String strRecordId  ='';
            if(String.isNotBlank(RecordId)){
                strRecordId = RecordId;
                if(strRecordId.length() > 15){
                    strRecordId = strRecordId.substring(0,15);
                    strRecordId = '\''+ strRecordId + '\'';
                    strId += strRecordId + '|';
                    
                }                        
            }
            else{
                strRecordId = '\' \'';
                strId += strRecordId + '|';
            }
        }
    }
    strId = strId.removeEnd('|');
    return strId ;
    
}
added 1094 characters in body
Source Link
samdev
  • 154
  • 2
  • 10

You can use the join method from String class like below to get the string of ids seperated by '|' operator:

String.join( new List<String>(String.join(new List<id>(setId), ',').split(',')) , '|' ));

EDIT: you can add the entries to a new list and then join them. Also check for isNotBlank for every entry in the for loop:

     public static string getString(Set<Id> setId){
            String strId = '';
            if(setId != null && setId.size() > 0 )
            {
                List<String> finalList= New List<String>();
                for(Id RecordId :setId)
                {
                    if(String.isNotBlank(RecordId)){
                        String strRecordId = RecordId;
                        if(strRecordId.length() > 15){
                            strRecordId = strRecordId.substring(0,15);
                            finalList.add(strRecordId);
                        }                        
                    }
                    else{
                        finalList.add(''); 
                    }
                }
            }
             strId  = String.join(finalList,'|');
             return strId ;
            
        }

You can use the join method from String class like below to get the string of ids seperated by '|' operator:

String.join( new List<String>(String.join(new List<id>(setId), ',').split(',')) , '|' ));

You can use the join method from String class like below to get the string of ids seperated by '|' operator:

String.join( new List<String>(String.join(new List<id>(setId), ',').split(',')) , '|' ));

EDIT: you can add the entries to a new list and then join them. Also check for isNotBlank for every entry in the for loop:

     public static string getString(Set<Id> setId){
            String strId = '';
            if(setId != null && setId.size() > 0 )
            {
                List<String> finalList= New List<String>();
                for(Id RecordId :setId)
                {
                    if(String.isNotBlank(RecordId)){
                        String strRecordId = RecordId;
                        if(strRecordId.length() > 15){
                            strRecordId = strRecordId.substring(0,15);
                            finalList.add(strRecordId);
                        }                        
                    }
                    else{
                        finalList.add(''); 
                    }
                }
            }
             strId  = String.join(finalList,'|');
             return strId ;
            
        }
Source Link
samdev
  • 154
  • 2
  • 10
Loading