我已经发起了一个触发器,它会在广告系列上的Field上更新时触发,并限制用户在拒绝记录时将“注释”字段留空。
这是我的触发器代码:
trigger RequireRejectionComment on Campaign (before update)
{
Map<Id, Campaign > rejectedStatements
= new Map<Id, Campaign>{};
for(Campaign inv: trigger.new)
{
Campaign oldInv = System.Trigger.oldMap.get(inv.Id);
if ((oldInv.BR_ApprovalStatusRegulatory__c != 'Reprovado'
&& inv.BR_ApprovalStatusRegulatory__c == 'Reprovado')||
(oldInv.BR_ApprovalStatusLegal__c!= 'Reprovado' &&
inv.BR_ApprovalStatusLegal__c== 'Reprovado') )
{
rejectedStatements.put(inv.Id, inv);
}
}
if (!rejectedStatements.isEmpty())
{
List<Id> processInstanceIds = new List<Id>{};
for (Campaign invs : [SELECT (SELECT ID
FROM ProcessInstances
ORDER BY CreatedDate DESC
LIMIT 1)
FROM Campaign
WHERE ID IN :rejectedStatements.keySet()])
{
processInstanceIds.add(invs.ProcessInstances[0].Id);
}
// Now that we have the most recent process instances, we can check
// the most recent process steps for comments.
for (ProcessInstance pi : [SELECT TargetObjectId,
(SELECT Id, StepStatus, Comments
FROM Steps
ORDER BY CreatedDate DESC
LIMIT 1 )
FROM ProcessInstance
WHERE Id IN :processInstanceIds
ORDER BY CreatedDate DESC])
{
if ((pi.Steps[0].Comments == null ||
pi.Steps[0].Comments.trim().length() == 0))
{
Trigger.new[0].parentId.addError(' My error Message ');
//rejectedStatements.get(pi.TargetObjectId).addError(
// ' My error Message');
}
}
}
}
此触发器工作正常但在新页面上显示错误消息..
我的要求:错误消息应出现在记录或同一页面上,同时拒绝记录。
请建议,谢谢..
答案 0 :(得分:0)
Have you tried creating the validation within the apex page itself?
You can set the page item to have a validation that doesn't allow the page to be submitted if a specified page item is NULL.
Look for the validations section within the page-processing section when editing your page.
Here is a link to documentation regarding validations:
https://docs.oracle.com/database/121/HTMDB/bldr_validate.htm#HTMDB28931