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

Recent record from related list
Hi,
I need to write a trigger to get most recent record from related list "CampaignMember" and update to it a custom field on parent "Contact".Any Idea?
Thanks
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Hi,
I need to write a trigger to get most recent record from related list "CampaignMember" and update to it a custom field on parent "Contact".Any Idea?
Thanks
Two things comes in my mind when you say "most recent"
1) Most recently updated/created
2) Most recently viewed.
If you are looking for the second point then I don't think this is possible with apex and if you are looking for the first point then you can just query on "CmapaignMember" with limit 5/10 (which ever suits you) and DESC on lastModified Date.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Thanks Ankit for your reply.I need to get most recent created Campaign Member record from the related list of Contact and update the Campaign name to a field on Contact.Can you please post the trigger syntax.
Here is the logic which will help you to move ahead with the trigger code.
You can change "cm.Contact.Name" to the field name which you want to fill in Campaign Name.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Ankit,
This is really helpful. I saved the trigger with the following code:
I am wondering why this code is compiling when I don't have a Contact.Name custom field on my Contact object? Isn't the point to display the most recent Campaign Name in a custom field on the Contact record a user is viewing?
Also...don't you need a test class to support the trigger?