Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- General Development
- :
- Changing User when a field has been updated by ape...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Changing User when a field has been updated by apex code
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-18-2013 06:50 PM
Hi,
Whenever I use apex callout to update some field or even any apex trigger for that matter, the record history says that the field has been updated by the logged in user. This makes it sometime confusing to keep track on which fields the logged in users are actually updating . I understand that the apex code have run due to some actions by the logged in user but still is there any way to show in record history that a particular field is updated by apex .
Thanks,
Rahul
Solved! Go to Solution.
Re: Changing User when a field has been updated by apex code
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-19-2013 02:39 AM
You are right that changes caused by triggers will always show as being made from the user who caused the trigger to fire in the UI. There is no way to know for sure whether a particular field was changed in the UI or by a trigger, since trigger changes on their objects are part of the same "change set" as the UI changes.
If a trigger is updating a different record, then there is a way to know. If you add a custom field to the object, say 'date record changed by trigger', and 'track changes' on the field, then only set it during trigger execution. You'll be able to see those changes in the record change history.
For example, if you have a Contact trigger, that updates an Account record when something changes on the Contact, you can add a 'date changed by trigger' to Account. In the Contact trigger, add Account.date_changed_by_trigger__c = Date.Today().
This will not work if the trigger only updates the object being edited in the UI, since all the field changes will be tracked together.
Re: Changing User when a field has been updated by apex code
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-19-2013 11:58 AM
Thanks Jeff .
Can we do this if some webservice callout from some custom button on object pagelayout is updating fields? I mean, the button on click updates the same record (single object.)
Re: Changing User when a field has been updated by apex code
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-19-2013 12:06 PM
In that case I think you'll be OK since there are no other UI-driven field changes being made at the same time. The user chose to click the button, and may or may not make other field changes, but that's OK. Unlike an inline edit where several fields could be changed, and then a trigger changes one more.
Re: Changing User when a field has been updated by apex code
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-19-2013 01:24 PM
So while making a callout can we change the user context ? I mean, if anything gets updated due to callout results that can be shown in record history on behalf of a generic user (say Integration). This can help us.
I found that system.runas() can only work for test classes.
Re: Changing User when a field has been updated by apex code
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-19-2013 01:25 PM
Re: Changing User when a field has been updated by apex code
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-19-2013 01:28 PM
Thanks for clarification

