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
- :
- Unable to update parent field from child object.. ...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Unable to update parent field from child object.. Please help!!!!!! !!!!!!!!!
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-28-2012 05:18 AM - edited 03-29-2013 04:28 AM
Hi,
I need help in updating a parent record field with Yes or No value.
When I create a child record with lookup field value as hardcoded value, trigger get save but doesnt allow to save child record.
This is the code i am not able to save the child record. On child record I have visualforce page.
trigger PopulateDAA on DAA__c (after insert, after update)
{
set<id> DealIDs = new set<id>();
set<id> DdataIDs = new set<id>();
for(DAA__c l : trigger.new)
{
DealIDs.add(l.Deal__c);
}
List<Deal__c> deals= [select id, PovRate2530__
deals[0].PovRate2530__c = 'No';
for(DAA__c l : trigger.new)
{
if(l.Deal__c == 'Poverty Rates Greater Than 25 Percent')
{
deals[0].PovRate2530__c = 'Yes';
}
else
{
deals[0].PovRate2530__c = 'No';
}
}
update deals;
}
This code executes but doesnt work...
As i have VF page on child object its not allowing me to save the record.
I feel its a lookup field (Deal__c) so its not reading the value.. may be I am wrong.
Please help!!!!
Solved! Go to Solution.
Re: Unable to update parent field from child object.. Please help!!!!!! !!!!!!!!!
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-28-2012 12:08 PM - edited 12-28-2012 12:09 PM
if(l.NMTC_Deal__c == 'Poverty Rates Greater Than 25 Percent')
If NMTC_Deal__c is a Lookup field, you should compare it to an ID field or a String that represents an ID, not a plain text String.
If not, explain a little bit more how is your model (where is the lookup field), etc. and what is the business logic you want to achieve
If this post solves your problem/issue/question, please mark it as solution.
SFDC Certified Developer
Re: Unable to update parent field from child object.. Please help!!!!!! !!!!!!!!!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-28-2012 06:52 PM
Tweet us and we will help you:
@waveoc | @vatwaveoc
---------------------------------
__________
Re: Unable to update parent field from child object.. Please help!!!!!! !!!!!!!!!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-30-2012 09:09 AM
Re: Unable to update parent field from child object.. Please help!!!!!! !!!!!!!!!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-30-2012 09:46 AM
1. Have you tried both IDs? (15 and 18 characters long)
2. What is Robin? is that the value of the Name field in the parent record?
3. By this, are you trying to track changes performed on your "children" (details) records at parent Level? Is like an 'used' flag or something?
Regards.
If this post solves your problem/issue/question, please mark it as solution.
SFDC Certified Developer
Re: Unable to update parent field from child object.. Please help!!!!!! !!!!!!!!!
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-30-2012 11:45 AM - edited 03-29-2013 04:17 AM
Thanks very much for ur reply
1. Yes I tried with both the ID's, now my code is working one way its updating Parents record fields as Yes or No but everytime record is getting creted it updates all the fields of parent record as NO and only one as YES.
As I have used if else seperately, I created another code where I have used ElseIF statement though its giving me YES for perticular field but remaining field are getting value as BLANK. When there is no value there has to be a NO value. how to achieve that??
2. Robin is just a Record Name i.e. Parent record.
3. Yes I am trying to track changes made to child object on parent level in the form of YES and No Value not any Flag.
I have many fields on Parent as Text fields whenevr Trigger condition satisfies it should update parent field as Yes otherwise No.
Thanks in advance!!!!
Re: Unable to update parent field from child object.. Please help!!!!!! !!!!!!!!!
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-30-2012 12:27 PM - edited 03-29-2013 10:51 AM
Try something like
[code quotes removed by author's request]
(Changed deals from List to Map (so it becomes bulk friendly for objects that belong to different deals)
(Else statements removed, reason (correct me if my assumption is wrong)
You have object A pointing to object C (A->C) and object B pointing to object C (B->C), and you have two fields in C called modifiedA__c and modifiedB__c)
If the user updates A (trigger is executed and set modifiedA to 'Yes' and modifiedB to 'No'). [thats ok]
If after that, user updates B (trigger is executed and set modifiedA to 'No' and modifiedB to 'Yes'). [shouldn't modifiedA be kept to 'Yes'?. If so, that is why I removed the else statements].
)
Hope I made my self clear :S
Regards.
If this post solves your problem/issue/question, please mark it as solution.
SFDC Certified Developer
Re: Unable to update parent field from child object.. Please help!!!!!! !!!!!!!!!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-30-2012 10:49 PM
Thank you so much SeAlVa!!!!!!
You got it right.. Its working fine for me now.
On parent I took the field as Picklist and made it default as NO now its getting updated by trigger as YEs.
Thank you again.. :)

