Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Trigger to update grand child
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Trigger to update grand child
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 03:39 AM
Hi, I have written a trigger to update the grandchild whenevr the field in grand parent object updated..this trigger is however not updating the field ..please help me on this
trigger updateDev_Lead on Project__c(after update)
{
for(project__c prj: trigger.new)
{
if(trigger.oldmap.get(prj.Id).Dev_Lead_User__c!=tr
{
List<Task__c> Lsttask=new List<Task__c>();
Lsttask=[Select id,project__c from Task__c where project__c=: prj.Id];
for(Task__c thistask: Lsttask)
{
List<Root_Cause__c> lstRc=new List<Root_cause__c>();
lstRc=[select id,Dev_Lead__c from Root_Cause__c where id =:thistask.id];
List<Root_cause__c> RcToupdate=new List<Root_cause__c>();
for(Root_cause__c thisRc:lstRc)
{
thisRc.Dev_lead__c=prj.Dev_Lead_User__c;
RcToupdate.add(thisRc);
}
if(!RcToupdate.isempty()){
update RcToupdate;
}
}
}
}
}
Solved! Go to Solution.
Re: Trigger to update grand child
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 04:00 AM
In this section:
List<Root_Cause__c> lstRc=new List<Root_cause__c>();
lstRc=[select id,Dev_Lead__c from Root_Cause__c where id =:thistask.id];
List<Root_cause__c> RcToupdate=new List<Root_cause__c>();
you are selecting the root causes whose ID matches the task id - this is guaranteed to return no rows as no root causes will have that Id. You should be checking the related task id. Something like:
List<Root_Cause__c> lstRc=new List<Root_cause__c>();
lstRc=[select id,Dev_Lead__c from Root_Cause__c where Task_id__c =:thistask.id];
List<Root_cause__c> RcToupdate=new List<Root_cause__c>();
This assumes the id of the related task is stored in the Task_Id__c field - if its a different name, substitute that here.
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter
I don't respond to private messages/emails asking for help.
Take the Bob Buzzard Sobject Fields quiz.
Re: Trigger to update grand child
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 04:07 AM

