You need to sign in to do that
Don't have an account?
saad mechiche alami
Trigger before Update [I cannot update fields]
Hello everyone;
in the following code, I would like that some fields to be autopopulated when the status is equal to 'CAN'
In the code:
if(smc.status__c=='CAN')
the 2 fields are these ones:
smc.SVMXC__Canceled_On__c=datetime.now();
smc.SVMXC__Active__c=false;
When the trigger is launched nothing get updated.
Could you please help
Many thanks
in the following code, I would like that some fields to be autopopulated when the status is equal to 'CAN'
In the code:
if(smc.status__c=='CAN')
the 2 fields are these ones:
smc.SVMXC__Canceled_On__c=datetime.now();
smc.SVMXC__Active__c=false;
When the trigger is launched nothing get updated.
Could you please help
Many thanks
trigger ServiceContractCanceled_beforeInsert on SVMXC__Service_Contract__c (before update) { for(List<SVMXC__Service_Contract__c> IsCanceledServiceContract: [select Id,Status__c,ReasonForCancellation__c,SVMXC__Canceled_On__c,SVMXC__Active__c from SVMXC__Service_Contract__c where Id IN: Trigger.New]){ for(SVMXC__Service_Contract__c smc : IsCanceledServiceContract) { if(smc.status__c=='CAN') { if(smc.ReasonForCancellation__c==null){ Trigger.new[0].addError('Please set the reason for cancellation'); Trigger.new[0].ReasonForCancellation__c.addError('Reason for Cancellation should not be empty'); } smc.SVMXC__Canceled_On__c=datetime.now(); smc.SVMXC__Active__c=false; } } } }
so remove this :
for(List<SVMXC__Service_Contract__c> IsCanceledServiceContract: [selectId,Status__c,ReasonForCancellation__c,SVMXC__Canceled_On__c,SVMXC__Active__c from SVMXC__Service_Contract__c where Id IN: Trigger.New]){
and at line 6 use Trigger.New :
for(SVMXC__Service_Contract__c smc : Trigger.New )
Let me know if still issues.
Use below code: