In the example below MultiPicklist__c is a multi-select picklist field in Account object. In order to set values to multi-select picklist, first, we need to form a string with each selected value followed by ";" and then assign this string to the multi-select picklist field.
public class MutlipicklistFieldValue {
public MutlipicklistFieldValue () {
}
public void insertAccount() {
Account newAccount = new Account();
newAccount.name = 'Testing Multipicklist Value';
string values = 'A;B;D';
newAccount.MultiPicklist__c = values;
insert newAccount;
system.debug('newAccountnewAccount'+newAccount);
}
}
@Anudeep Thanks for the reply I was missing the party to get the picklist values in the test class. DescribeFieldResult describe = MyCustomObject__c.customfield__c.getDescribe(); List<PicklistEntry> avl = describe.getPicklistValues(); MyCustomObject__c. h1 = new MyCustomObject__c.(name='abc'); string fgh=avl[0].value+';'+avl[2].value+';'+avl[1].value; h1.customfield__c=fgh;
Here is an example.
In the example below MultiPicklist__c is a multi-select picklist field in Account object. In order to set values to multi-select picklist, first, we need to form a string with each selected value followed by ";" and then assign this string to the multi-select picklist field.
Let me know if it helps
Thanks,
Anudeep
first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST,
This error occurs when the picklist field referenced in the error message meets each of the following conditions:
- The referenced picklist field has 'Restrict picklist to the values defined in the value set' set to Enabled.
- The referenced picklist field is a dependent picklist.
- The page layout does not include both the controlling and dependent picklist fields.
- A default value is set for the referenced picklist field:
- If the object includes Record Types - This error occurs if the record type sets the default value.
- If the object does not include Record Types - This error occurs if the picklist field sets the value.
- All record types should have the newly create picklist selected in the Selected items section and not under available items.
- Initiate a Mass Quick Action with Predefined Value Set
- Any active trigger on the object where the field is used can give the same error.
Let me know if this helpshttp://https://help.salesforce.com/articleView?id=000320321&language=en_US&type=1&mode=1
Thanks,
Anudeep
Thanks for the reply
I was missing the party to get the picklist values in the test class.
DescribeFieldResult describe = MyCustomObject__c.customfield__c.getDescribe();
List<PicklistEntry> avl = describe.getPicklistValues();
MyCustomObject__c. h1 = new MyCustomObject__c.(name='abc');
string fgh=avl[0].value+';'+avl[2].value+';'+avl[1].value;
h1.customfield__c=fgh;
in this way I was able to get the code coverage.