• Alex Solodyankin
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I had some help putting a version of the below code together and am not sure why the code doesn't fire the 2nd and 3rd If statement when the first statement is false (having a null value in either the in the HS Electives field), even if the 2nd and/or 3rd are true. The 2nd and 3rd only fire when the first statement is true. I considered using Else If statements, but that stops the code from progressing when the first statement is true.

The goal of this code is to populate all of the 3 multi-select picklist electives desired fields into a single field, regardless of which of the 3 fields have values in them.
 
trigger UpdateAllElectivesMSPV1 on Case (before update) {
    for(Case c : Trigger.new) {
        

        if(!String.isBlank(c.S1_High_School_Electives__c)){
            List<String> pickValuesHS = c.S1_High_School_Electives__c.split(';');
            String pickValuesHSStr ='' ;
            for(String HSstr : pickValuesHS){
                         pickValuesHSStr = pickValuesHSStr + '\n' + HSstr;
            }
c.Electives_Desired__c =  pickValuesHSStr.abbreviate(500);


       if(!String.isBlank(c.Middle_School_Elec__c)){
            List<String> pickValuesMS = c.Middle_School_Elec__c.split(';');
            String pickValuesMSStr ='' ;
            for(String MSstr : pickValuesMS){
                         pickValuesMSStr = pickValuesMSStr + '\n' + MSstr;
          }


              c.Electives_Desired__c = pickValuesHSStr.abbreviate(500) + '\n' + pickValuesMSStr.abbreviate(500);

 if(!String.isBlank(c.S1_Elementary_School_Elective_Selection__c)){
            List<String> pickValuesES = c.S1_Elementary_School_Elective_Selection__c.split(';');
            String pickValuesESStr ='' ;
            for(String ESstr : pickValuesES){
                         pickValuesESStr = ESstr;            
         }


              c.Electives_Desired__c = pickValuesHSStr.abbreviate(500) + '\n' + pickValuesMSStr.abbreviate(500) + '\n' + pickValuesESStr.abbreviate(500);
        }
}
}
}
}

 
Our organization has been in dire need of being able to convert a multi-select picklist value on our Case into text fields. We've discovered we can split the array by ';', though we're seeing multiple ways people have done it and are not able to create a working trigger. We are hoping to limit the trigger based on the record type, 'Applications', but could simply limit the trigger based on the multi-select picklist being blank, though not sure about a simple way to do that. We are trying to populate the text field: S1_High_School_Electives__c with the potentially multiple values of High_School_Electives_Desired__c. I tried manipulating the code from https://developer.salesforce.com/forums?communityId=09aF00000004HMGIA2#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F0000000B1n0IAC

I'm not sure if I also need to create the class like that post has, and how that would be embedded in the trigger. The error I get is that a DML statement cannot operate on a trigger.new. I'm thinking a SOQL query could be made instead as well.
trigger UpdateHSElectivesMSPV1 on Case (after update) {



for(Case c : Trigger.new) {
String pickValuesStr;
    if(!String.isBlank(c.High_School_Electives_Desired__c)){
        List<String> pickValues = c.High_School_Electives_Desired__c.split(';');
        for(String str : pickValues){
            if(String.isBlank(pickValuesStr)){
                pickValuesStr = str;
                }
                 else{
                     pickValuesStr = pickValuesStr + '\n' + str;
                    } 
                }
            
  c.S1_High_School_Electives__c = pickValuesStr;

}

  Update c;
  }
  }

 
I had some help putting a version of the below code together and am not sure why the code doesn't fire the 2nd and 3rd If statement when the first statement is false (having a null value in either the in the HS Electives field), even if the 2nd and/or 3rd are true. The 2nd and 3rd only fire when the first statement is true. I considered using Else If statements, but that stops the code from progressing when the first statement is true.

The goal of this code is to populate all of the 3 multi-select picklist electives desired fields into a single field, regardless of which of the 3 fields have values in them.
 
trigger UpdateAllElectivesMSPV1 on Case (before update) {
    for(Case c : Trigger.new) {
        

        if(!String.isBlank(c.S1_High_School_Electives__c)){
            List<String> pickValuesHS = c.S1_High_School_Electives__c.split(';');
            String pickValuesHSStr ='' ;
            for(String HSstr : pickValuesHS){
                         pickValuesHSStr = pickValuesHSStr + '\n' + HSstr;
            }
c.Electives_Desired__c =  pickValuesHSStr.abbreviate(500);


       if(!String.isBlank(c.Middle_School_Elec__c)){
            List<String> pickValuesMS = c.Middle_School_Elec__c.split(';');
            String pickValuesMSStr ='' ;
            for(String MSstr : pickValuesMS){
                         pickValuesMSStr = pickValuesMSStr + '\n' + MSstr;
          }


              c.Electives_Desired__c = pickValuesHSStr.abbreviate(500) + '\n' + pickValuesMSStr.abbreviate(500);

 if(!String.isBlank(c.S1_Elementary_School_Elective_Selection__c)){
            List<String> pickValuesES = c.S1_Elementary_School_Elective_Selection__c.split(';');
            String pickValuesESStr ='' ;
            for(String ESstr : pickValuesES){
                         pickValuesESStr = ESstr;            
         }


              c.Electives_Desired__c = pickValuesHSStr.abbreviate(500) + '\n' + pickValuesMSStr.abbreviate(500) + '\n' + pickValuesESStr.abbreviate(500);
        }
}
}
}
}

 
Our organization has been in dire need of being able to convert a multi-select picklist value on our Case into text fields. We've discovered we can split the array by ';', though we're seeing multiple ways people have done it and are not able to create a working trigger. We are hoping to limit the trigger based on the record type, 'Applications', but could simply limit the trigger based on the multi-select picklist being blank, though not sure about a simple way to do that. We are trying to populate the text field: S1_High_School_Electives__c with the potentially multiple values of High_School_Electives_Desired__c. I tried manipulating the code from https://developer.salesforce.com/forums?communityId=09aF00000004HMGIA2#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F0000000B1n0IAC

I'm not sure if I also need to create the class like that post has, and how that would be embedded in the trigger. The error I get is that a DML statement cannot operate on a trigger.new. I'm thinking a SOQL query could be made instead as well.
trigger UpdateHSElectivesMSPV1 on Case (after update) {



for(Case c : Trigger.new) {
String pickValuesStr;
    if(!String.isBlank(c.High_School_Electives_Desired__c)){
        List<String> pickValues = c.High_School_Electives_Desired__c.split(';');
        for(String str : pickValues){
            if(String.isBlank(pickValuesStr)){
                pickValuesStr = str;
                }
                 else{
                     pickValuesStr = pickValuesStr + '\n' + str;
                    } 
                }
            
  c.S1_High_School_Electives__c = pickValuesStr;

}

  Update c;
  }
  }