Thursday, October 27, 2011

Cross Object Formulas

I have found that using Cross Object Formulas is an extremely helpful way to make updates within Salesforce.com. A big problem that I have run into with Salesforce.com is the inability to track back through the owner of the record to retrieve information from the User record on the current record in question.
For example, I have a need to know what Role an owner of a case has in order to perform some additional logic. Ideally, I would be able to track up through the owner as it is related to the case already. Unfortunately Salesforce does not allow us to do this.
Fortunately using Cross Object Formulas we can get around this. Here is a simple way that I have been able to use the Current User to identify the role of the owner on a record.

This example is how I pull the Role for the Current Owner of the record.

  1. Create a new text field to store the Role on the case record.
  2. Create a new workflow on the case object that is updated Every time a record is created or edited. It should also have a rule criteria of  Not( ISNULL (CreatedDate)). Essentially this will cause the workflow to fire every time the record is touched.
  3. Next we create the field update. Here we can use this syntax If(Ownerid = $User.ID, $UserRole.Name, Priorvalue (Owner_Role__c)) Essentially what we are doing here is performing a check against the current user who is editing the record. If they are the owner of the record then it will pull the Owner Role from their user record. If they are not then it will leave the field that we created with whatever the prior value was.
Activate your workflow and you should be good to go. The great thing about this is that it follows strictly to the security policy of Salesforce, so you have to actually be the owner of the record in order for this to work. Logging in as a user will not work to trigger the update. You can do a similar operation with any of the User record fields even custom fields using the Current User selection.

No comments:

Post a Comment