I am trying to leverage a custom setting to bypass some validation for a specific update in some APEX. This is not test code coverage so I do not need to create the record first, I should simply be able to query the existing record. I am actually using this same code to query/change the same custom setting in another non-test code class with no issue, however, I am getting the following error in this class:
System.QueryException: List has no rows for assignment to SObject
the part of the code that is causing this is the first line of the following:
Automation_FO__c autoFO1 = [select Id, Validation_Rules_DISABLED__c
from Automation_FO__c
limit 1];autoFO1.Validation_Rules_DISABLED__c = true;
update autoFO1;
try
{
update FOsToUpdate;
update FLIsToUpdate;
}
catch(DmlException e)
{
system.debug(LoggingLevel.ERROR, e.getMessage());
}
// Change the Custom Setting back to put validation rules back in to effect. case 00012193.
Automation_FO__c autoFO2 = [select Id, Validation_Rules_DISABLED__c
from Automation_FO__c
limit 1];
autoFO2.Validation_Rules_DISABLED__c = false;
update autoFO2;
I have also heard that putting this in a list might get rid of this error but I do not want to have an empty list returned as this will defeat the purpose of what I am trying to accomplish. Any thoughts as to what is causing this or how to resolve it would be appreciated!
in responce to Das:
I using Hierarchy rather than List custom settings so that I can use them in a validation rule (I believe that List custom settings cannot be referenced in validation rules) . Thus if I create a record, it needs to be specific to a role or profile, which I do not want, I want this to work for everyone. Using "Run As" might be a workaround for this though.
However, even then, this record has no name that I am aware of so I am not sure what to reference in the place where you referenced 'ALPHA'.
There are default org level values that you can check and uncheck and I would like to access these but again, I do not know how to reference these by name as you did with the 'ALPHA'. Any thoughts?