• Jared Rosenberg
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
Good morning folks!

I've got a custom object (Work Order Line) that has a restricted picklist field by the name of Reason Code (Reason_Code__c).  This field is validated as other objects move through different statuses, so in the process of creating unit tests I need to be able to assign a value for it.  Unfortunately, it's giving me a lot of trouble doing that.

The first available value of the picklist, and the one I'm trying to test with, has a value of '01 - Charged - per contract/entitlement' and api name of '01 - Charged - per contract/entitlement'

In a test class, I've tried setting it by giving it a string literal.  That errored with:

System.DmlException: Update failed. First exception on row 0 with id a238E000001AQxpQAG; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, bad value for restricted picklist field: 01 - Charged - per contract/entitlement: [Reason_Code__c]

In desperation, I've even fetched the picklist value from the object and fed it right back to it.  That fails with the same error.  Code snippet follows:

        SVMXC__Service_Order_Line__c orderLine1 = new SVMXC__Service_Order_Line__c();
        orderLine1.SVMXC__Service_Order__c = workOrder1.Id;
        orderLine1.Date_parts_are_required_by__c = Date.today();
        orderLine1.SVMXC__Requested_Quantity2__c = 10;
        orderLine1.Consumed_Qty__c = 3;
        orderLine1.Returned_Qty__c = 0;
        orderLine1.SVMXC__Product__c = objLineProd.id;
        insert orderLine1;
        List<String> reasonCodeLabels = new List<String>();
        Schema.DescribeFieldResult fieldResult = SVMXC__Service_Order_Line__c.Reason_Code__c.getDescribe();
        List<Schema.PicklistEntry> reasonCodes = fieldResult.getPicklistValues();
        for(Schema.PicklistEntry ple : reasonCodes) {
            reasonCodeLabels.add(ple.getValue());
        }
        String reason = reasonCodeLabels.get(0);
        orderLine1.Reason_Code__c = reason;
        update orderLine1;
        workOrder1.SVMXC__Order_Status__c= 'Ready to Invoice';
        update workOrder1;
        objCase.Status = 'Ready to Invoice';
        update objCase;
        Test.stopTest();

This errors on the line: orderLine1.Reason_Code__c = reason; with the same error above.

I can't figure out why it won't let me set the picklist to a value I just took from the picklist accepted values.  Can anyone assist with this?

Thanks!
Good afternoon, folks.

I'm in the process of trying to consolidate the SOQL calls within a trigger of a particularly difficult sObject.  This sObject has enough code running on it that we're pretty regularly hitting the 101 error--so it's time to clean up and bulkify where possible.

I've run the following to fill a map with an sobject, and the children of that sobject.  Let's assume for the moment that Service_Order_Line is a child of Service_Order with a many-to-one relationship, and I've filtered this down so I'm only getting one Service_Order and maybe 5 or 10 Service_Order_Lines:

map<ID, Service_Order__c> testResults = new map<ID, Service_Order__c>([select ID, Name, (select ID, Name from Service_Order_Line__r) from Service_Order__c']);

Further down in the trigger, I'll need to reference the child objects, but I can't seem to find a syntax to make it work.  How would I write the following to loop through the children of testResults?

for(Service_Order_Line childrenOfTestResults : testResults.Service_Order_Line__r) {
    system.debug(childrenOfTestResults.Name);
}
Good morning folks!

I've got a custom object (Work Order Line) that has a restricted picklist field by the name of Reason Code (Reason_Code__c).  This field is validated as other objects move through different statuses, so in the process of creating unit tests I need to be able to assign a value for it.  Unfortunately, it's giving me a lot of trouble doing that.

The first available value of the picklist, and the one I'm trying to test with, has a value of '01 - Charged - per contract/entitlement' and api name of '01 - Charged - per contract/entitlement'

In a test class, I've tried setting it by giving it a string literal.  That errored with:

System.DmlException: Update failed. First exception on row 0 with id a238E000001AQxpQAG; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, bad value for restricted picklist field: 01 - Charged - per contract/entitlement: [Reason_Code__c]

In desperation, I've even fetched the picklist value from the object and fed it right back to it.  That fails with the same error.  Code snippet follows:

        SVMXC__Service_Order_Line__c orderLine1 = new SVMXC__Service_Order_Line__c();
        orderLine1.SVMXC__Service_Order__c = workOrder1.Id;
        orderLine1.Date_parts_are_required_by__c = Date.today();
        orderLine1.SVMXC__Requested_Quantity2__c = 10;
        orderLine1.Consumed_Qty__c = 3;
        orderLine1.Returned_Qty__c = 0;
        orderLine1.SVMXC__Product__c = objLineProd.id;
        insert orderLine1;
        List<String> reasonCodeLabels = new List<String>();
        Schema.DescribeFieldResult fieldResult = SVMXC__Service_Order_Line__c.Reason_Code__c.getDescribe();
        List<Schema.PicklistEntry> reasonCodes = fieldResult.getPicklistValues();
        for(Schema.PicklistEntry ple : reasonCodes) {
            reasonCodeLabels.add(ple.getValue());
        }
        String reason = reasonCodeLabels.get(0);
        orderLine1.Reason_Code__c = reason;
        update orderLine1;
        workOrder1.SVMXC__Order_Status__c= 'Ready to Invoice';
        update workOrder1;
        objCase.Status = 'Ready to Invoice';
        update objCase;
        Test.stopTest();

This errors on the line: orderLine1.Reason_Code__c = reason; with the same error above.

I can't figure out why it won't let me set the picklist to a value I just took from the picklist accepted values.  Can anyone assist with this?

Thanks!
Good morning folks!

I've got a custom object (Work Order Line) that has a restricted picklist field by the name of Reason Code (Reason_Code__c).  This field is validated as other objects move through different statuses, so in the process of creating unit tests I need to be able to assign a value for it.  Unfortunately, it's giving me a lot of trouble doing that.

The first available value of the picklist, and the one I'm trying to test with, has a value of '01 - Charged - per contract/entitlement' and api name of '01 - Charged - per contract/entitlement'

In a test class, I've tried setting it by giving it a string literal.  That errored with:

System.DmlException: Update failed. First exception on row 0 with id a238E000001AQxpQAG; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, bad value for restricted picklist field: 01 - Charged - per contract/entitlement: [Reason_Code__c]

In desperation, I've even fetched the picklist value from the object and fed it right back to it.  That fails with the same error.  Code snippet follows:

        SVMXC__Service_Order_Line__c orderLine1 = new SVMXC__Service_Order_Line__c();
        orderLine1.SVMXC__Service_Order__c = workOrder1.Id;
        orderLine1.Date_parts_are_required_by__c = Date.today();
        orderLine1.SVMXC__Requested_Quantity2__c = 10;
        orderLine1.Consumed_Qty__c = 3;
        orderLine1.Returned_Qty__c = 0;
        orderLine1.SVMXC__Product__c = objLineProd.id;
        insert orderLine1;
        List<String> reasonCodeLabels = new List<String>();
        Schema.DescribeFieldResult fieldResult = SVMXC__Service_Order_Line__c.Reason_Code__c.getDescribe();
        List<Schema.PicklistEntry> reasonCodes = fieldResult.getPicklistValues();
        for(Schema.PicklistEntry ple : reasonCodes) {
            reasonCodeLabels.add(ple.getValue());
        }
        String reason = reasonCodeLabels.get(0);
        orderLine1.Reason_Code__c = reason;
        update orderLine1;
        workOrder1.SVMXC__Order_Status__c= 'Ready to Invoice';
        update workOrder1;
        objCase.Status = 'Ready to Invoice';
        update objCase;
        Test.stopTest();

This errors on the line: orderLine1.Reason_Code__c = reason; with the same error above.

I can't figure out why it won't let me set the picklist to a value I just took from the picklist accepted values.  Can anyone assist with this?

Thanks!
Good afternoon, folks.

I'm in the process of trying to consolidate the SOQL calls within a trigger of a particularly difficult sObject.  This sObject has enough code running on it that we're pretty regularly hitting the 101 error--so it's time to clean up and bulkify where possible.

I've run the following to fill a map with an sobject, and the children of that sobject.  Let's assume for the moment that Service_Order_Line is a child of Service_Order with a many-to-one relationship, and I've filtered this down so I'm only getting one Service_Order and maybe 5 or 10 Service_Order_Lines:

map<ID, Service_Order__c> testResults = new map<ID, Service_Order__c>([select ID, Name, (select ID, Name from Service_Order_Line__r) from Service_Order__c']);

Further down in the trigger, I'll need to reference the child objects, but I can't seem to find a syntax to make it work.  How would I write the following to loop through the children of testResults?

for(Service_Order_Line childrenOfTestResults : testResults.Service_Order_Line__r) {
    system.debug(childrenOfTestResults.Name);
}