You need to sign in to do that
Don't have an account?
tengel
Retrieve Activity.WhoId.RecordTypeId
Hello, Apex newbie here.
Can anyone help me along in the right direction? I would like to update a a custom Activity checkbox field to TRUE if the WhoId of an Activity equals a certain record type. In my non-Apex layman's formula terms, it's something like this:
IF Activity.WhoId.RecordTypeId = "01260000000LyEL", My_Checkbox__c = TRUE, FALSE
Any ideas?
Thanks!
Replace all instance of "lead" with "contact" if that is the object you're using instead. Don't use an ID value, because that will make your work more challenging later. Use the Developer Name instead.
This is a basic aggregate-query-update pattern. First, I gather all record IDs that are leads. Then, I query those leads for their record type. Finally, I update the tasks with the information. Note that I can assign a boolean result directly to a checkbox, which removes the need to say "if(...) ... checkbox = true; else checkbox = false;" This comes in handy when you're trying to bump up your code coverage.
Edit: Fixed typo.
All Answers
Replace all instance of "lead" with "contact" if that is the object you're using instead. Don't use an ID value, because that will make your work more challenging later. Use the Developer Name instead.
This is a basic aggregate-query-update pattern. First, I gather all record IDs that are leads. Then, I query those leads for their record type. Finally, I update the tasks with the information. Note that I can assign a boolean result directly to a checkbox, which removes the need to say "if(...) ... checkbox = true; else checkbox = false;" This comes in handy when you're trying to bump up your code coverage.
Edit: Fixed typo.
Thanks, @sfdcfox!
I moved your code into my sandbox and tested it out on lead, but I keep getting this error:
Sorry, I am a newb or else I'd probably be better at troubleshooting this myself :(
Wow, thank you @sfdcfox, that trigger ROCKS. Can I be a complete mooch and ask for a test class? If it's any consolation, I understood the trigger so clearly that I should be able to also understand the test and then never have to bother wizards like you on these boards again (or at least won't have to for a while!).
Your milage may vary (validation rules, required fields, etc), but this is the basic framework I'd use.
Don't worry about hassling us; we do this voluntarily.