• Prachi Goel 17
  • NEWBIE
  • 5 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 0
    Questions
  • 3
    Replies
I have a trigger that works, but I want to add criteria.
If the Sales Engineering Request “Status” does not equal “Approved” or “Unable to Meet Request”, then trigger this.
How do I modify this? Thank you for your help.

My Trigger:
trigger FeedCommentTest on FeedComment (after insert) 
{
    for(FeedComment f : Trigger.New)
    {
        if(UserInfo.getProfileId()  == '00e6w000000FjiUAAS')
        {
            Sales_Engineering_Request__c SalesEngineeringRequestToUpdate = [SELECT ID FROM SALES_ENGINEERING_REQUEST__c WHERE ID =: f.ParentId];
            SalesEngineeringRequestToUpdate.Status__c = 'Approved';
            Update SalesEngineeringRequestToUpdate;
        }          
    }
}
Trigger having all the events so in handler there are two methods which i not able to cover how to cover this methods:-

public void afterDelete(SObject so) {
    }
    
    public void afterUndelete(SObject so) {
    }
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!
Trigger having all the events so in handler there are two methods which i not able to cover how to cover this methods:-

public void afterDelete(SObject so) {
    }
    
    public void afterUndelete(SObject so) {
    }
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!