You need to sign in to do that
Don't have an account?
Unable to update parent field from child object.. Please help!!!!!!!!!!!!!!!
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__c from Deal__c where id in :DealIDs ];
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!!!!
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.
All Answers
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
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.
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!!!!
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.
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.. :)