You need to sign in to do that
Don't have an account?

Apex Help
Hello:
I have two unrelated objects that have the same Name value that I am attempting to write a code for to update a field.
I am trying to update the CBW_Rev_Share__c value using a formula with a value from Site__c
Below is my code. I am not getting a value back in the CBW_Rev_Share__c field.
trigger RevShareUpdate on Penetration_Summary__c (before insert, before update) { Set<String> penSumName = new Set<String>(); for (Penetration_Summary__c pen : Trigger.new) { if(pen.Current__c == TRUE) { penSumName.add(pen.Name); } } Set<String> releaseNameStrs = new Set<String>(); Map<String, Release__c> releaseSumMap = new Map<String, Release__c>(); for(Release__c release1:[Select ID, Name, CBW_Rev_Share__c, CBW_Rev_Share__r.Tier_One__c from Release__c Where Name IN: penSumName ]) { releaseSumMap.put(release1.Name, release1); releaseNameStrs.add(release1.Name); } List<Penetration_Summary__c> penForUpdate = new List<Penetration_Summary__c>(); for(Penetration_Summary__c c:[Select Id, Name, CBW_Rev__c, CBW_Rev_Share__c from Penetration_Summary__c where Name In : releaseNameStrs ]) { if(releaseSumMap.containsKey(c.Name)) { if(releaseSumMap.get(c.Name).CBW_Rev_Share__r.Tier_One__c != null && c.CBW_Rev__c != null) c.CBW_Rev_Share__c = (releaseSumMap.get(c.Name).CBW_Rev_Share__r.Tier_One__c * c.CBW_Rev__c); else c.CBW_Rev_Share__c = 0; penForUpdate.add(c); } } }
Thanks,
Hampton
HAmpton,
run this below code and post you debug log.
you can open debug logs
adminstravitve set up ---------> Deboglog---------> click " new" button and select your name, once you added your name go and modify any penetration_summary__c the check the debug logs.
All Answers
Thanks for the quick response. I just tried it again and still am not getting a value in CBW_Rev_Share__c.
I have $1,000 in CBW_Rev__c and 3.25 in Release__c.CBW_Rev_Share__r.Tier_One__c
CBW_Rev_Share__c and CBW_Rev__c are currency fields. Release__c.CBW_Rev_Share__r.Tier_One__c is a percent field. If that is important to this.
Any other thoughts?
Thanks,
Hampton
Hampton
write a system.debug('*************CBW :'+ CBW_Rev__c);
Add like this after evey value and got debug logs
setup-> monitoring->debuglogs.
run your code and check refresh the debuglog page and check in the recent log for the values you were expecting
you can learn about the values that are comming .
If this answers your question make this as solution and give kudos plz
HAmpton,
run this below code and post you debug log.
you can open debug logs
adminstravitve set up ---------> Deboglog---------> click " new" button and select your name, once you added your name go and modify any penetration_summary__c the check the debug logs.
I'm haven't looked closely at this code, but whatever changes were made worked. I now have a vaule in the field that is the correct value.
Thank you so much for your help.
Hampton
This working fantastic, thank you again for your help...now I need to write a test class to get the code coverage up to 100%...and I have no idea where to start. Can you at least help me get started and I will take care of the rest?
Thanks,
Hampton