You need to sign in to do that
Don't have an account?
Prashant Ranjan 12
triggers on Account
we have 2 objects Account and Dsignation
parent object:Account
Child object: Designation
Relationship :Lookup(Field name "Account__C" on Designation object)
If an Account has Designation with Title CEO(Field name="Title__c") then the Account field "Area__c" cannot be blank
parent object:Account
Child object: Designation
Relationship :Lookup(Field name "Account__C" on Designation object)
If an Account has Designation with Title CEO(Field name="Title__c") then the Account field "Area__c" cannot be blank
trigger demo on Account (after update) {
if(trigger.isAfter && trigger.isUpdate ){
system.debug('hello buddy');
demohandler.validationdemo(trigger.old);
}
}
handler class
public class demohandler {
public static void validationdemo(List<Account> acc){
Set<Id> idSet = new Set<Id>();
for(Account acc1: acc){
idSet.add(acc1.id);
}
List<Account> accList = [Select id, Area__c,(select id ,Title__c from Designations__r) from Account where Id IN: idSet];
for(Account act:Designation__c.){
for(Designation__c deg:accList.act){ //Account has designation with Title CEO (field name= Title__c)
if(deg.Title__c == 'CEO' && act.Area__c == ''){
// Account field Area cannot be blank
act.addError('Area should not be blank');
}
}
}
}
}
but i am getting an error. does any one provide me a right solutons
Please try the below updated code:
Trigger: (Use before update)
Apex Class:
Thanks,
Maharajan.C
why you had written this act.Designations__r.size()>0
can you explain
[Select id, Area__c,(select id ,Title__c from Designations__r where Title__c='CEO') from Account where Id IN: idSet];
The above code is working or not?
Thanks,
Maharajan.C