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

trigger.old clarification
can we use trigger.old in after insert event ???
More over, my code is to create a new invoice record when the "active checbox" is selected true in the coustomer obj and the old value shuld be unchecked. event has to update evvent where in my trigger works fine in after Insert how come pls explain
trigger test1 on Apex_Customer__c (after Insert) {
list <APEX_Invoice__c> upinv = new list <APEX_Invoice__c>();
for(Apex_Customer__c newcus : trigger.new)
{
if(newcus.APEX_Active__c == True && trigger.oldmap.get(newcus.id).APEX_Active__c != True )
{
APEX_Invoice__c newinv = new APEX_Invoice__c();
newinv.APEX_Customer__c = newcus.Id;
upinv.add(newinv);
}
}
insert upinv;
}
More over, my code is to create a new invoice record when the "active checbox" is selected true in the coustomer obj and the old value shuld be unchecked. event has to update evvent where in my trigger works fine in after Insert how come pls explain
trigger test1 on Apex_Customer__c (after Insert) {
list <APEX_Invoice__c> upinv = new list <APEX_Invoice__c>();
for(Apex_Customer__c newcus : trigger.new)
{
if(newcus.APEX_Active__c == True && trigger.oldmap.get(newcus.id).APEX_Active__c != True )
{
APEX_Invoice__c newinv = new APEX_Invoice__c();
newinv.APEX_Customer__c = newcus.Id;
upinv.add(newinv);
}
}
insert upinv;
}
We can not use trigger.old in after insert event. It returns null as there is no old instance.
Take a look on trigger context variable (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm)
Thanks,
Dhanya