You need to sign in to do that
Don't have an account?
Glenn Balmonte
Apex Trigger assigning Record Type for Child Record
Hello Experts,
Need your assistance. We have a trigger that wil automatically create child records every time that the Parent Record Type is selected (e.g. If User selected the Parent Record Type "AIM"). I just need your inputs on how I can set all of these Child Records to one record type which is also AIM. Here is the code:
//trigger that creates a new production task for every new AIM Project with SEO products
trigger AutoCreateProductionTask on SFDC_Project__c (after insert) {
List<Production_Task__c> newRecord = new List<Production_Task__c>();
List<String> namePT = new List<String>();
namePT.add('Website Audit Report and Recommendations');
namePT.add('Keyword Research');
namePT.add('Competitor Research');
namePT.add('Run page speed loading test and make improvements');
namePT.add('Run site on validator and fix broken links and html errors');
namePT.add('Run crawl test and redirect any obsolete urls');
namePT.add('Keyword mapping, meta data creation and implementation');
namePT.add('Text content creation');
namePT.add('Upload optimized text content, insert and highlight ketwords');
namePT.add('Optimize keywords in footer links');
namePT.add('Optimize alt tags of images');
namePT.add('Create or improve HTML sitemap page');
namePT.add('Add breadcrumbs navigation on inner pages');
namePT.add('Add Google+ Authorship code on inner pages');
namePT.add('Create Google Places listing');
namePT.add('Submit site to web directories');
namePT.add('Create Google Webmaster Tools profile');
namePT.add('Create Google Analytics profile');
namePT.add('Create and submit xml sitemap to Google');
namePT.add('Create and publish 1 Press Release');
for (SFDC_Project__c aim : Trigger.new) {
if (aim.RecordTypeID == '012300000009FLk')
if (aim.Product_Service__c == 'SEO - Premium'|| aim.Product_Service__c == 'SEO - Pro'|| aim.Product_Service__c == 'SEO - Starter')
{
for(Integer i = 0; i < namePT.size(); i++){
Production_Task__c aimTask = new Production_Task__c();
aimTask.Name = namePT [i];
aimTask.Due_Date__c = Date.today().addDays(30);
aimTask.Project__c = aim.Id;
aimTask.Instructions__c = 'test';
newRecord.add(aimTask);
}
}
insert newRecord;
}
}
Any assistance is greatly appreciated. Thank you.
Need your assistance. We have a trigger that wil automatically create child records every time that the Parent Record Type is selected (e.g. If User selected the Parent Record Type "AIM"). I just need your inputs on how I can set all of these Child Records to one record type which is also AIM. Here is the code:
//trigger that creates a new production task for every new AIM Project with SEO products
trigger AutoCreateProductionTask on SFDC_Project__c (after insert) {
List<Production_Task__c> newRecord = new List<Production_Task__c>();
List<String> namePT = new List<String>();
namePT.add('Website Audit Report and Recommendations');
namePT.add('Keyword Research');
namePT.add('Competitor Research');
namePT.add('Run page speed loading test and make improvements');
namePT.add('Run site on validator and fix broken links and html errors');
namePT.add('Run crawl test and redirect any obsolete urls');
namePT.add('Keyword mapping, meta data creation and implementation');
namePT.add('Text content creation');
namePT.add('Upload optimized text content, insert and highlight ketwords');
namePT.add('Optimize keywords in footer links');
namePT.add('Optimize alt tags of images');
namePT.add('Create or improve HTML sitemap page');
namePT.add('Add breadcrumbs navigation on inner pages');
namePT.add('Add Google+ Authorship code on inner pages');
namePT.add('Create Google Places listing');
namePT.add('Submit site to web directories');
namePT.add('Create Google Webmaster Tools profile');
namePT.add('Create Google Analytics profile');
namePT.add('Create and submit xml sitemap to Google');
namePT.add('Create and publish 1 Press Release');
for (SFDC_Project__c aim : Trigger.new) {
if (aim.RecordTypeID == '012300000009FLk')
if (aim.Product_Service__c == 'SEO - Premium'|| aim.Product_Service__c == 'SEO - Pro'|| aim.Product_Service__c == 'SEO - Starter')
{
for(Integer i = 0; i < namePT.size(); i++){
Production_Task__c aimTask = new Production_Task__c();
aimTask.Name = namePT [i];
aimTask.Due_Date__c = Date.today().addDays(30);
aimTask.Project__c = aim.Id;
aimTask.Instructions__c = 'test';
newRecord.add(aimTask);
}
}
insert newRecord;
}
}
Any assistance is greatly appreciated. Thank you.
Take a look on the below code where i can bold the fonts.
One more thing don't use hard coded ids in the code it will fail if you are doing so.
Let me if it is helpful.
Peace.
All Answers
Take a look on the below code where i can bold the fonts.
One more thing don't use hard coded ids in the code it will fail if you are doing so.
Let me if it is helpful.
Peace.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger AutoCreateProductionTask caused an unexpected exception, contact your administrator: AutoCreateProductionTask: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.AutoCreateProductionTask: line 29, column 1
Make sure that you have recordtype on SFDC_Project__c named as 'AIM'.
Can you please take out describe call from loop.
Thanks
Sandeep Singhal