- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- 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
02-18-2013 06:50 PM
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 .
Solved! Go to Solution.
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.
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.)
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.
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.