You need to sign in to do that
Don't have an account?
Update a text field to null if a picklist field has been updated
Hello!
I hope all of you are doing well. I have 15 picklist fields and if a user chose the "Other" value, the user will have to specify as to why they have chosen "Other" and this information will be in a text field. Below is only an example
Picklist Field A -> If User chose "Other" in Picklist Field A, a Text Field A - Other would pop up
Picklist Field B -> If User chose "Other" in Picklist Field B, Text Field B - Other would pop up
I am trying to create a custom coding that would update the Text Fields to null if the Picklist Field values are not set to "Other".
Below is the Apex Class that I have created:
public class PicklistUpdateHandler {
public static void updateTextFieldsToNull(List<Ribbonfish__Title__c> records) {
List<Ribbonfish__Title__c> recordsToUpdate = new List<Ribbonfish__Title__c>();
for (Ribbonfish__Title__c record : records) {
if (record.Ribbonfish__SMUR_on_AuthorsWebpage__c != 'Other' && record.Ribbonfish__SMUR_on_AuthorsWebpage__c != record.Ribbonfish__SMUR_on_AuthorsWebpage__c) {
record.Ribbonfish__SMURAuthorsPersonalWebpageOther__c = null;
recordsToUpdate.add(record);
}
if (record.Ribbonfish__SMUR_onDepartmentalWebpage__c != 'Other' && record.Ribbonfish__SMUR_onDepartmentalWebpage__c != record.Ribbonfish__SMUR_onDepartmentalWebpage__c) {
record.Ribbonfish__SMURDepartmentalWebpageOther__c = null;
recordsToUpdate.add(record);
}
}
if (!recordsToUpdate.isEmpty()) {
update recordsToUpdate;
}
}
}
Just a heads up, this is my first time creating Apex and I am not certified as Salesforce Developer. Everyone is welcome to share their thoughts and I'm looking forward to your response.
Thank you and stay safe!
-Aleina :)
Can you expand on the problem you are facing with your apex class? Seems to me it is written to handle your use case.