
1) Priority Field (Parent)
2) Reason(Child to Priority & Parent to Status)
3) Status (Child to Reason)
there is lookup relation between above 3 objects. Trigger must be fire on Reason object when the condition is Priority is P1 and status is Closed then Reason field should be disable.
trigger onUpdateOfObjectB on Object_B__c(Before insert,before update) {
set<String> Idval=new set<String>();
set<Integer> Ids=new set<Integer>();
for (Object_B__c ct: trigger.new)
{
idval.add(ct.Lookup_Object_A__c);
ids.add(ct.Id);
}
List Aclist=[select Id,Priority__c from Object_A__c where Id =:Idval];
List Bclist=new List();
List Cclist=[select Lookup_Object_B__c,Status__c from Object_C__c where Lookup_Object_B__c=:ids];
for(Object_A__c ac: Aclist)
{
for(Object_C__c cc: Cclist)
{
if(ac.Priority__c=='P1' && cc.Status__c=='Closed')
{
System.debug('SDFGsdf sdfsdf');
cc.addError('Your custom error message');
}
}
}
}
Can nybody help with the correct code for this trigger
3 réponses

try this,not sure
if(ac.Priority__c=='P1' && cc.Status__c=='Closed')
{
Object_B__c.Reason field=disabled;
or
Object_B__c.Reason field=hide;
}