You need to sign in to do that
Don't have an account?
Praveenchandu
Create 3 custom Objects a --> b -->c c is grand child a is grand parent display the count of c in grandparent A using trigger in lookup relation
Create 3 custom Objects
a --> b -->c
c is grand child
a is grand parent
display the count of c in grandparent A
using trigger
in lookup relation
a --> b -->c
c is grand child
a is grand parent
display the count of c in grandparent A
using trigger
in lookup relation
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Grand Parent: Grand_Parent__c
Child of Grand Parent: Child_Of_GP__c
Grand Child (Child of Child_Of_GP__c): Grand_Child__c
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Grand Parent: Grand_Parent__c
Child of Grand Parent: Child_Of_GP__c
Grand Child (Child of Child_Of_GP__c): Grand_Child__c
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Try this code ,
Grand Parent: cObj
Child of Grand Parent: aObj
Grand Child : aObj
countGrantChild__c : Field to show count of cObj in grandparent aObj Hope this helps..
Thanks for Your Time.
I'm getting this error at line 2
Error: Compile Error: Unexpected token '<'. at line 2 column 7
trigger cObj_trigger on Grand_Child_c__c (after insert,after delete) {
map<id,Child_Of_GP_c__c> b_map=map <id,Child_Of_GP_c__c> ([select id,name,a from Child_Of_GP_c__c]);
map<id,Grand_Parent_c__c> a_map= map<id,Grand_Parent_c__c> ([select id,name,countGrantChild__c from Grand_Parent_c__c]);
list<Grand_Parent_c__c> update_a_list=new list<Grand_Parent_c__c>();
Grand_Parent_c__c new_A=new Grand_Parent_c__c();
Child_Of_GP_c__c new_B=new Child_Of_GP_c__c();
for (Grand_Child_c__c cc : Trigger.new) {
if(b_map.get(cc.b)!=null)
{
new_B=b_map.get(cc.b);
if(a_map.get(new_B.a)!=null)
{
new_A=a_map.get(new_B.a);
if(new_A.countGrantChild__c==null)
new_A.countGrantChild__c=0;
else
{
if(Trigger.isDelete)
new_A.countGrantChild__c= new_A.countGrantChild__c-1;
if(Trigger.isInsert)
new_A.countGrantChild__c= new_A.countGrantChild__c+1;
update_a_list.add(new_A) ;
}
}
}
}
if(update_a_list.size>0)
update update_a_list;
}
Change these two lines
With these lines(Sorry I missed new keyword)
Hope this helps...
Sorry again i'm getting the bellow Error.
Error: Compile Error: Variable does not exist: b at line 14 column 25
I'm getting the below error
Error: Compile Error: Variable does not exist: b at line 14 column 25
Thank You.
Please update Replace 'a' in query with your corresponding lookup field(relationship to Grand_Parent_c__c) in Child_Of_GP_c__c
Replace every cc.b with your corresponding lookup field(relationship to Child_Of_GP_c__c) in Grand_Child_c__c
eg: if your lookup field api name is Child_Of_GP_c__c then use cc.Child_Of_GP_c__c instead of cc.b
Replace every cc.a with your corresponding lookup field(relationship to Grand_Parent_c__c) in Child_Of_GP_c__c
eg:if your lookup field api name is Grand_Parent_c__cthen use cc.Grand_Parent_c__c instead of cc.a
Here a & b are my lookup field in my child and parent objects
Hope this helps...
Thank You for ur help but unfortunatly again its not working.
I'm getting the following errors.
Error: Compile Error: Variable does not exist: countGrantChild_c__c at line 29 column 37
Error: Compile Error: Variable does not exist: size at line 38 column 26
Thank you for ur help But unfortunately it is not working here is the code @Khan Anas