You need to sign in to do that
Don't have an account?
DannyTK
Need assistance writing a test class
Hello Community,
Have a simple trigger to update the owner of a custom object (Sales_Order__c) back to the createdby when status is updated to 'Sales Order Completion':
trigger SalesOrderUpdateOwner on Sales_Order__c (before Update)
{
for(Sales_Order__c sc : trigger.new)
{
Sales_Order__c oldrecord = trigger.oldMap.get(sc.id);
if(sc.Status__c == 'Sales Order Completion' )
{
sc.OwnerId = sc.CreatedById ;
}
}
}
I just cannot seem to be able to save a test class (i'm also not a developer, so that makes it more challenging to know what i'm doing). Was trying to create a class where I Insert a new Sales_Order__c record, with the Status__c = 'Sales Order Submitted'. Then I tried to add an update on the Status__c = 'Sales Order Completion' (which should trigger the code), but nothing takes (various error messages based on how i'm saving it). Not sure if it's because the status is updated via Javascript button and i have to account for that somehow on the testclass (I get to the testclass where i can create the record, but cannot seem to be able to update the record). Any assistance is appreciated...
Have a simple trigger to update the owner of a custom object (Sales_Order__c) back to the createdby when status is updated to 'Sales Order Completion':
trigger SalesOrderUpdateOwner on Sales_Order__c (before Update)
{
for(Sales_Order__c sc : trigger.new)
{
Sales_Order__c oldrecord = trigger.oldMap.get(sc.id);
if(sc.Status__c == 'Sales Order Completion' )
{
sc.OwnerId = sc.CreatedById ;
}
}
}
I just cannot seem to be able to save a test class (i'm also not a developer, so that makes it more challenging to know what i'm doing). Was trying to create a class where I Insert a new Sales_Order__c record, with the Status__c = 'Sales Order Submitted'. Then I tried to add an update on the Status__c = 'Sales Order Completion' (which should trigger the code), but nothing takes (various error messages based on how i'm saving it). Not sure if it's because the status is updated via Javascript button and i have to account for that somehow on the testclass (I get to the testclass where i can create the record, but cannot seem to be able to update the record). Any assistance is appreciated...
here is the trigger and test class... i removed the oldrecord line in the trigger as you are not using it..
also you might need to assign any required fields before inserting the sales order in the test class as i mentioned in the commented line
All Answers
here is the trigger and test class... i removed the oldrecord line in the trigger as you are not using it..
also you might need to assign any required fields before inserting the sales order in the test class as i mentioned in the commented line
thanks for cleaning up my trigger as well, works perfectly.
another thumbs up sir.
-d