Monday, October 31, 2011

Submit for Approval Button

The other day I was looking for a way to create a button for submitting a record for approval I wanted to do this so that I could have it on the top of the record instead of in the related lists. I found a bit of java script that allows me to do this in a custom button. For those of you that are looking to do this it's very easy to do. Here's how:


  1. Go to your object and select the Buttons and Links section.
  2. Click to Create a New button.
  3. Give the button a name
  4. Choose a Detail Page Button 
  5. Select Execute JavaScript as the behavior.
  6. Select OnClick JavaScript as the Content Source
  7. In the code area enter the following code block. *Please note that you can edit the pop alert text to fit your scenario as well as change the name of the object to the object you would like to work with. In this example, I am using the Case object as an alternative means for escalating cases.*

    {!REQUIRESCRIPT('/soap/ajax/23.0/connection.js')}
    
    if ((Modal.confirm && Modal.confirm('Once you escalate this case, you must recall the approval before you can edit it. Continue?')) || (!Modal.confirm && window.confirm('Once you submit this case, you must recall the approval before you can edit it. Continue?'))) navigateToUrl('/p/process/Submit?id={!Case.Id}&retURL=%2F{!Case.Id}');
    

  8. Finally Add the button to the page layout.
Please note that this button will only work if you have an approval process setup for the object that you are creating it on. If there is not one, the button will obviously not submit the record through an approval process that does not exist. 

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.

Wednesday, October 26, 2011

Salesforce.com Entitlements

For those of you looking to understand a little bit more about Salesforce.com Entitlements and how it works for the service cloud, here are a few things that I discovered as I worked to enable it for my org.

Milestones do NOT auto-close, so if you are looking to use Entitlements as a way to track SLA's on cases, you will need to implement some code. Never fear, most of the work has already been done for you on Developerforce.com. Here are some links to some code that I found helpful in implementing entitlements:
  1. http://wiki.developerforce.com/index.php/Case_Milestones_Utilities_Class
  2. http://wiki.developerforce.com/index.php/Auto-completion_of_Case_Milestones_with_Triggers
  3. http://wiki.developerforce.com/index.php/Auto-completion_Resolution_Time_Milestones_with_Triggers
I realize that this is code that you would have to use to do this, but I have found really no other way. It's almost as though Salesforce took us 90% of the way and stopped for some reason. I'm not quite sure why.

The next problem that I ran into with Entitlements is deployment. I already developed the entire thing within my Sandbox and then I wanted to deploy to production through Change Sets. Big problem, I see no way within the declarative interface to deploy entitlements from one org to another. I checked using Change Sets and Creating a package and I found nothing. I was DEVASTATED. How could I possibly have done all of this work in getting everything just right to find out that there is no way to move that work from my Sandbox to production. I then went through the tedious task of moving data manually from one sandbox to another. It wasn't until after I deployed all of this work that I found another way.

I have not yet been able to fully test this but, if anyone does, please let me know if it works for you. You simply have to use the Salesforce.com IDE. Entitlements are a meta data component that is not pulled automatically when you setup a new project. So here are the steps to do it:
  1. Open the Salesforce.com IDE and create a New Project
  2. Name your project whatever you choose, enter your credentials and security token and click next.
  3. Now on the next screen select the option for "Selected metadata components" and hit choose.
  4. You will notice after the IDE fetches the metadata that there are a lot of things available for selection here that may make life easier. We are going to specifically go and get the Entitlements Metadata. You can do this by clicking on the checkbox that appears to the left of "Entitlement Templates"
  5. You should now be taken back to the project page and it should look like this:
  6. Click Finish
You should now be able to deploy this through the IDE. Please remember that I had to do mine manually and have not had a chance to test this since. For anyone that does please let me know if this works for you.