function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Joe DoyleJoe Doyle 

Can you help me write a Trigger using the Last Login Field?

I have a report that uses the contact record and I want to add the User object field "Last Login" to this report.

I believe I can do this with a trigger. Please let me know if I am on the right track. I should create a custom field on the contact object and use a trigger to populate the Last Login info into that custom field? Can you please help me write this code?

Thanks
Biswa RayBiswa Ray
Hi Joe,

I would suggest you to leverage Record Type instead of writing a trigger. If you want to show fields from different objects in a single report, then best way achieve this is through "Report Type". 

Please check if there is any existing standard report type which gives you provision to select last login field from User record. If not then you can create a custom report type and display both contact and user objects fields in report.  

Please check below help link to get started with salesforce report types ,

https://help.salesforce.com/HTViewHelpDoc?id=reports_report_type_setup.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=reports_report_type_setup.htm&language=en_US" target="_blank)
https://help.salesforce.com/apex/HTViewHelpDoc?id=reports_defining_report_types.htm (https://help.salesforce.com/apex/HTViewHelpDoc?id=reports_defining_report_types.htm" target="_blank)

hope it helps. 

Cheers!!


 
Joe DoyleJoe Doyle
Hi Biswa,

Can you have the field "Last Login" in a custom report type? When I look at the User Object Fields, there is no field for Last Login. That is the field I need to get into another report.

Thanks,
Joe
Biswa RayBiswa Ray
Hi Joe,

I think you are trying to find this field on User Object. If yes , then there you might not see that field. But when you will try to create custom report type that field will appear for selection. I tried  creating a custom report type in my developer org and found "Last Login" field to select from user object. I had selected "User" as primary object and Contact as secondary object while creating this report type. 


User-added image

Can you please let me know  how you are creating custom report type in your org? 

Regards,
Biswa