6

I have a scenario that need to check whether the record has been modified or not. If the record ir modified by any other user except user A. Need to show an error Message.

Currently i have added a method in before update to throw a error message if the UserInfo.GetUserid != user A.id.

Any other possbilities? is there a way to find out whether a record has been modified or not?

More info:

If Status = Inactive, Except User A no other user can edit the Custom object record.

2
  • 1
    Can you explain you use case in more detail? Do you want to block updates to the record, or do you want to detect them afterwards? Oct 21, 2013 at 4:22
  • I have added more information
    – goodForce
    Oct 21, 2013 at 6:59

4 Answers 4

3

You can do this with a validation. If you need to exclude more than one users, you can also add a boolean field (e.g AllowEdit__c') on the User record and use this as part of your validation.

So Something like this:

!ISNEW() && Status = inactive && $User.Id != 'theuserid'

or

!ISNEW() && Status = inactive && !$User.AllowEdit__c

2
  • Here only we can make sure that only User A modifies the record. But is there way to find out whether the record has been changed or not?
    – goodForce
    Oct 21, 2013 at 9:31
  • Validations are evaluated on Insert and Updates. This means the validation will be checked on any update. See here for more details help.salesforce.com/…
    – ManSpan
    Oct 21, 2013 at 9:42
1

There are a few ways I see.

First is restricting access on a trigger for this type of records with simple checking user who're making changes

if (UserInfo.getUserId().equals('A.id')) {
    // perform actions
} else {
    // show error msg
}

The next option is using read only access for all users for this records except user A. There are 2 ways, the first one is a restricting access on the role level and add special role for user A. The second one is restricting access on the profile level and creation special profile with access for records for user A, or (more correct approach) restrict access for all profiles and create a special permission set which will allow access for this records and assign it to user A.

The approach with trigger might be good if you're currently using triggers and do not use a role hierarchy or don't want to create a permission sets. But from my point of view the approach with restricting on a profile/permission set level is more preferable.

Also if you're using VF in this scenario the additional options for checking exist.

0

If you want a formula to show if a record has been edited then try:-

LastModifiedDate <>  CreatedDate
1
  • using this method we can identify only once, but it will not work for every time. May be we can crate another custom field with last modified date and compare with that every time. it requires additional field.
    – goodForce
    Oct 22, 2013 at 3:45
0

There are a number of ways to see if a record has been updated, though you don't provide much info on your use case. IF you want to prevent users from editing a record in a certain state, this can be done with a validation rule. Perhaps something like:

State_Field == 'Locked' && $Profile.Name != 'Special Admin Profile'

With the message:

This account is locked and can only be modified by a Special Admin

Another idea would be to use a workflow rule to change the Record Type based on appropriate criteria, and set different permissions/layouts for the new record type.

Here's other some potential answers depending on what you're trying to do:

Do you want to report on the last user who modified a record, with the date?

  • Run a report on the last modified by field.

Do you want to run reports to see who has made what changes to certain fields?

  • add history tracking to the fields, run a report off the history object.

Do you want to prevent all users except for a certain role or profile from editing based on a field status?

  • Use a validation rule that takes the profile or role into account.

Have an alert on the detail page if the record is changed while you're viewing it?

  • Use a visualforce page inserted on the page layout that grabs the last modified date on page load, then periodically polls the database to see if it's been modified, or use the streaming API.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .