You need to sign in to do that
Don't have an account?
raju123
check children s exist through validation
Hi,
Let us suppose i have two objects(A,B) with look up relationship. A is parent and B is child.
Now i want to write a validation that if A doesn't have childrens give an error message.
I am trying the following in "A" Object but its not working
A's Id<> $ObjectType.B.Fields.A__c
Can any body help me Please please........................ How Can i Know Childrens exist or not through validation.
If above is not correct what is the significance of $ObjectType. please help me
please help me out
I think performing a simple SOQL query could do the trick.
List<B> children = [select Id from B where B.A__c = A.Id];
if(children.size()==0){
// display error
}
Summary Hello Raju,
Create a roll up summary which counts the children if count is zero you fire validation rule
I don't have much information regarding $ObjectType's use in Validation rule.
For your question, you cannot write validation rule to check for child records if you have lookup relationship. You need master-detail relationship. Change the lookup relationship to master-detail. Create a roll-up summary field in parent to calculate no. of child records, check through validation rule for count=0.
Also, you may also want to exclude records that are newly created (or created now) from this validation rule, as you cannot have child records if parent is not yet created.
You will either need to change it to master detail or use a trigger to throw an error message.