function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nikhil Vodapally 5Nikhil Vodapally 5 

Trigger creating "null" alongside other values

Hi Peeps,
I'm new to writing Triggers but managed to make my Trigger work the way its designed to work. However, it is populating NULL alongside default values. 
The Trigger updates a Multi-select picklist with default values when a checkbox is checked. 
trigger AutoPopulateProDiscussed on Meeting_Call_Report__c (before insert, before update) {
    if(trigger.isInsert || trigger.isUpdate){
        for (Meeting_Call_Report__c mcr : Trigger.new){
        if(mcr.Benchmark_Reform__c == True && mcr.ProDiscussedTriggerHelper__c == False){
            mcr.Products_Discussed__c += ';€STR;SOFR (Secured overnight financing rate)';
            mcr.ProDiscussedTriggerHelper__c = True;
    }
        }
        
    }
}

Can someone help me remove the NULL value please?
Regards,
Nikhil 
Best Answer chosen by Nikhil Vodapally 5
Prabhat Sharma 6Prabhat Sharma 6
Hi Nikhil,

Replace this line mcr.Products_Discussed__c += ';€STR;SOFR (Secured overnight financing rate)'; as below 
 
if(mcr.Products_Discussed__c!=null)
    mcr.Products_Discussed__c += ';€STR;SOFR (Secured overnight financing rate)';
else
    mcr.Products_Discussed__c = '€STR;SOFR (Secured overnight financing rate)';

 

All Answers

Prabhat Sharma 6Prabhat Sharma 6
Hi Nikhil,

Change this line mcr.Products_Discussed__c += ';€STR;SOFR (Secured overnight financing rate)'; as below
mcr.Products_Discussed__c = '€STR;SOFR (Secured overnight financing rate)';


 
Nikhil Vodapally 5Nikhil Vodapally 5
Hi Prabhat,

Thanks for the answer but I need the multiselect picklist field to default to the values in the Trigger in addition to the values the User selects whilst creating/updating the record. Can you help?
Prabhat Sharma 6Prabhat Sharma 6
Hi Nikhil,

Add the Null check before adding the values when there are exisiting values in the field. 
and in else add the line which I posted earlier. 
 
Nikhil Vodapally 5Nikhil Vodapally 5
Hi Prabhat,
Apologies, I dont understand. :-( 
Prabhat Sharma 6Prabhat Sharma 6
Hi Nikhil,

Replace this line mcr.Products_Discussed__c += ';€STR;SOFR (Secured overnight financing rate)'; as below 
 
if(mcr.Products_Discussed__c!=null)
    mcr.Products_Discussed__c += ';€STR;SOFR (Secured overnight financing rate)';
else
    mcr.Products_Discussed__c = '€STR;SOFR (Secured overnight financing rate)';

 
This was selected as the best answer
Nikhil Vodapally 5Nikhil Vodapally 5
Many thanks Prabhat, really appreciate your help with my query. Cheers bud!