0

below is my json where i am inserting the case record.

Status is standard field and the values are (New,Working,closed).

but if send the values other than the above values in json ,still its creating the records,but i wanted to throw an error. in custom field if i choose restricted picklist option its trwoing an exception,but not for standard picklist values. Please suggest

{
       "status" : "N",
       "origin" : "AIMS",
       "Custom_picklist":"Not allowed"
}

globalDesesr(string picklst){
    Schema.DescribeFieldResult fieldResult =case.picklst.getDescribe();
    List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    set <String> allOpts = new set <String> ();
    for(Schema.picklistEntry f:ple)    
    {    
        allOpts.add(f.getValue());        
    }

    return allOpts;   
}
2
  • 1
    What is restricted field option ?
    – MIX DML
    Commented Mar 13, 2018 at 8:10
  • how to check it for standard fields?
    – tarun
    Commented Mar 13, 2018 at 8:37

1 Answer 1

1

Just create a validation rule on your status field. This validation will make sure if you enter any other value except the above three value it will not allow to save record.

NOT(ISPICKVAL(status , 'New')) && NOT(ISPICKVAL(status , 'Working')) && NOT(ISPICKVAL(status , 'Closed'))
12
  • is there any way in apex class only i can fix it?
    – tarun
    Commented Mar 13, 2018 at 9:12
  • 1
    @tarun. Check the status value in apex and if didn't match then just throw error. Commented Mar 13, 2018 at 9:19
  • I guess in apex its not good solution,because there may be possibility that new value can be added,In that case we need to change the code and add it in validation.Is there any way where we can restrict values like restricted options for custom picklist
    – tarun
    Commented Mar 13, 2018 at 9:28
  • 1
    You can use describe to get the status value dynamically and then compare with json inputs. Commented Mar 13, 2018 at 9:43
  • any sample code?thanks in advance
    – tarun
    Commented Mar 15, 2018 at 5:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .