You need to sign in to do that
Don't have an account?
Forrest Muldune
Apex Trigger - Approval Process - Approve or Reject
All,
I created an Apex Trigger below, but I assume it is firing after a user selects the "Submit" button. I would like for this trigger to fire after someone selects either the " Approve " button or " Reject " button.
I would appreciate your help
trigger TriggerApprover on Matter__c (before update) {
if(trigger.isUpdate){
List<Matter__c> MatterList = [Select id,
(Select Id,
IsPending,
ProcessInstanceId,
TargetObjectId,
StepStatus,
OriginalActorId,
ActorId,
RemindersSent,
Comments,
IsDeleted,
CreatedDate,
CreatedById,
SystemModstamp
FROM ProcessSteps
ORDER BY CreatedDate DESC)
From Matter__c
WHERE Id IN : Trigger.new];
if(MatterList.size() > 0){
for(Matter__c mat : MatterList){
for(Matter__c mat1 : Trigger.new) {
//check copy comment is true
if(mat.id == mat1.id && mat1.Copy_Comment__c) {
if (mat.ProcessSteps.size() > 0) {
mat1.Approver_Comment__c = mat.ProcessSteps[0].Comments;
mat1.copy_comment__c = false;
}
}
}
}
}
}
}
I created an Apex Trigger below, but I assume it is firing after a user selects the "Submit" button. I would like for this trigger to fire after someone selects either the " Approve " button or " Reject " button.
I would appreciate your help
trigger TriggerApprover on Matter__c (before update) {
if(trigger.isUpdate){
List<Matter__c> MatterList = [Select id,
(Select Id,
IsPending,
ProcessInstanceId,
TargetObjectId,
StepStatus,
OriginalActorId,
ActorId,
RemindersSent,
Comments,
IsDeleted,
CreatedDate,
CreatedById,
SystemModstamp
FROM ProcessSteps
ORDER BY CreatedDate DESC)
From Matter__c
WHERE Id IN : Trigger.new];
if(MatterList.size() > 0){
for(Matter__c mat : MatterList){
for(Matter__c mat1 : Trigger.new) {
//check copy comment is true
if(mat.id == mat1.id && mat1.Copy_Comment__c) {
if (mat.ProcessSteps.size() > 0) {
mat1.Approver_Comment__c = mat.ProcessSteps[0].Comments;
mat1.copy_comment__c = false;
}
}
}
}
}
}
}
You can sue Trigger.isBefore or Trigger.isAfter condition.
-Thanks
Ashlekh Gera
The updates you provided to me worked.
The other problem I am experiencing is that I have an email alert that is connected to this approval. In the Trigger, it takes the "Comments" when the approver either approves or rejects the record on custom object matter__c . the comments are copied to the Approver_Comment__c (long text) on custom object matter__c, but the email is sent to the user containing the previous comments , not the updated comments.
For example, if the values " 1,2,3" already exist in the Approver_Comment__c and the approver writes in new comments "4,5,6" and approves or rejects the record, the updates comments "4,5,6" will not be sent to the email, the old values " 1,2,3" will be sent only.