You need to sign in to do that
Don't have an account?
Kerstin Koehler
Have records created on Children Accounts associated to a Parent Account
Hello All!
I need help determining the best way to solve a business need.
We have a Director of National Accounts that creates a promotion (custom object) at the HQ Account Record. The goal is to replicate that promotion record to the children that are tied to that parent HQ so that all individual owners of those child records can reference and see what promotion has been authorized at the top HQ level by our Director of National Accounts.
Premier support said I would need some coding, but i do not have any experience. Any ideas would be greatly appreciated of how I could accomplish this buisness need. Thank you in advance!!
I need help determining the best way to solve a business need.
We have a Director of National Accounts that creates a promotion (custom object) at the HQ Account Record. The goal is to replicate that promotion record to the children that are tied to that parent HQ so that all individual owners of those child records can reference and see what promotion has been authorized at the top HQ level by our Director of National Accounts.
Premier support said I would need some coding, but i do not have any experience. Any ideas would be greatly appreciated of how I could accomplish this buisness need. Thank you in advance!!
An AFTER INSERT, AFTER UPDATE trigger would be ideal for you to achieve this.
However, you need to take extra care to avoid cyclic triggers because you will be inserting / updating records in the same (Promotion) object as the trigger itself.
I have couple of questions here. Based on your answers I can help you out with the trigger.
1. Does this promotion created on HQ Account has to go through any kind of approval process, before made available for the Child accounts? Or, can the promotion for child accounts be created as soon as the HQ promotion is created?
2. Are you using the default ParentId based relationship in Account object?
3. What happens when the HQ promotion is updated at a latet point of time? Do the child promotions also go through the same changes?
4. Will all the values, except the Account, be the same for the HQ and Child promotions?
Let me know.
1. No, there will not be any type of approval process. The Director of National accounts will just create a Promotion record and click save which should start the process/trigger.
2. Yes I am using the default Parent Account Field on the Account Object
3. I asked our Director, and he said that 99.9% of the time he will not go back in and make a change to the promotion. So if we dont need to build that logic in then I would say leave it out, but if not too difficult to write the logic in, it probably wouldnt hurt to add.
4. Yes, all the values will be the same. Whatever is entered at the HQ point, will also need to be the same on the child - easily mapped fields
Side note - while speaking with our Director today he brought up another point that I was curious if we could add. He would select States authorized for this promotion - is there a way that based on the states he selects the promotions will only replicate to the children accounts that are in those specific states?
Again, if that is way too complicated, we can just write it to replicate to all then I would just really highlight the field of AUTHORIZED ONLY IN THE FOLLOWING STATES: __,___,__.
Thank you again for all of your help! I truly appreciate it!
Here is the sample trigger for you. There are couple of important points to take care of.
1. Allowed States - I have added an IF condition in line 19 to check if the child account belongs to an allowed state.
I have assumed that the "Allowed States" field in Promotion__c is a multi-picklist field and it's API name is Allowed_States__c.
Change the field name, if it is different.
2. Between line 24 and 27, you have to add all your Promotion__c fields in the format mentioned.
I have already added Account__c and Name fields here, take care of the rest.
If there are any differences in the API names of the Custom object or Custom fields, you need to change the code accordingly.
Let me know how it goes.
I copied and pasted the code along with the adding in the other fields and this is waht I have so far. Hopefully you can open this image and zoom in (didnt know hwo to copy and paste the code like you did)
I am however receiving an error message -
1) addPromotionsToChildAccounts - line 6 - expecting a semi-colon, found'}'
My other question to you would be will I need to have test coverage or code coverage - or a test class? for this trigger?
Thank you again! you are a life saver!
You are on track. I just missed a semi colon in the line 5.
Can you add a ; in the end of the line 5?
It should look like this after adding the semi colon.
On a different note about posting code here, do you see a button with "< >" symbol in the top of this editor?
Click on it. When the popup opens, just paste your code there and say OK.
Let me know how it goes.
that worked to fix the problem on line 6, however I am now experiencing another error message on line 21.
objNewPromotion.Account__c = objAccount;
(error is saying Illegal assignment from Account to Id)
Note* our Account Field on the Promotion Object is a Master -Detail Lookup custom field.
Thanks again for you help with this!
thank you in advance! I appreciate the help!