You need to sign in to do that
Don't have an account?

Update a record through custom button - JS PROBLEM
I have a record that currently has Status__c='Draft'
When I click the Start button, i want status to change to 'In Progress'
I have used following JS code to achieve this
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var p = new sforce.SObject('Product_Order__c');
p.id = "{!Product_Order__c.Id}";
p.Status__c = "In Progress";
result = sforce.connection.update([p]);
location.reload(true);
But, in Apex Trigger, I want to do some complex stuff when status changes from Draft to In Progress.
In my afterUpdate event, I am hooking on
Product_Order__c newPO = (Product_Order__c)o;
Product_Order__c oldPO = (Product_Order__c)o;
system.debug(newPO.Status__c);
system.debug(oldPO.Status__c);
if (newPO.Status__c.equals('In Progress') && newPO.Status__c != oldPO.Status__c)
newInProgressPO.put (newPO.Id, newPO.RecordType.Name);
However, these two User Debugs show that both old and new statuses are 'In Progress' so my Map is always empty.
Does anybody have any ideas?
When I click the Start button, i want status to change to 'In Progress'
I have used following JS code to achieve this
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var p = new sforce.SObject('Product_Order__c');
p.id = "{!Product_Order__c.Id}";
p.Status__c = "In Progress";
result = sforce.connection.update([p]);
location.reload(true);
But, in Apex Trigger, I want to do some complex stuff when status changes from Draft to In Progress.
In my afterUpdate event, I am hooking on
Product_Order__c newPO = (Product_Order__c)o;
Product_Order__c oldPO = (Product_Order__c)o;
system.debug(newPO.Status__c);
system.debug(oldPO.Status__c);
if (newPO.Status__c.equals('In Progress') && newPO.Status__c != oldPO.Status__c)
newInProgressPO.put (newPO.Id, newPO.RecordType.Name);
However, these two User Debugs show that both old and new statuses are 'In Progress' so my Map is always empty.
Does anybody have any ideas?
Right now both New and old value seems to be assigned same way:
Product_Order__c newPO = (Product_Order__c)o;
Product_Order__c oldPO = (Product_Order__c)o;
Normally to fetch old value we use Trigger.Old or Trigger.OldMap so it is written like I hope this would resolve your issue, if you still face issues then please share full code.
Thanks
All Answers
Right now both New and old value seems to be assigned same way:
Product_Order__c newPO = (Product_Order__c)o;
Product_Order__c oldPO = (Product_Order__c)o;
Normally to fetch old value we use Trigger.Old or Trigger.OldMap so it is written like I hope this would resolve your issue, if you still face issues then please share full code.
Thanks
Thank you!