0

I have been tasked with tracking the length of time it takes to fill in a salesforce form. Without using a visualforce page is there a way to set the value of a field as the form opens.

Essentially the management would like to see how long it takes to complete parts of a form. As soon as the "new" button is clicked I want to save the value into a field (record created isn't useful here as it is stored when the record is saved and I have tried formula fields but the same applies).

For reference the field will be a Date/Time so the normal formula would be NOW(). Apologies if my assumption this should be a "formula" field is wrong.

Thanks, Alex

4
  • How are you controlling the actions of the form? Will this be done via Apex?
    – Dan Jones
    Commented Oct 19, 2015 at 9:27
  • At the minute nothing but standard salesforce functionality
    – n34_panda
    Commented Oct 19, 2015 at 9:28
  • Understood. Is the form externally facing? Or are you talking about, say, creating an Account/Contact in Salesforce? How long it takes to get through the Page Layout for example?
    – Dan Jones
    Commented Oct 19, 2015 at 9:30
  • Its internally facing but the management want to understand why some staff members take a lot less time than others and this field would be to simply tack the entire duration spent on a record
    – n34_panda
    Commented Oct 19, 2015 at 9:31

2 Answers 2

1

After clarifying a few things with you and hoping I understand the kind of thing you're after, I can't see how you'd do this without going through one of two ways (although someone might well be a tad more innovative than myself):

Visalforce Page and Apex

I'll get this one out of the way first because I know you say that...

Without using a visualforce page is there a way to set the value of a field as the form opens.

... But it's still worth considering. You're probably already aware that you could capture the current date/time when the form opens. Something like this in your controller (be sure to test this first if you were to use it, I haven't tested it myself) should do the job:

public DateTime theDate {
  get {
    return System.now();
  };
  set;
}

You could then pass this value into a DateTime field in Salesforce and compare that with, say, the CreatedDate of the form to get the difference. Theoretically, this value should be earlier than the CreatedDate value.

The only reason I still suggest this is that personally I would say this would be the cleanest and probably easiest way of doing it.

JavaScript Button

This way that wouldn't involve you needing the use of a VF page would be to use a Controller. The JS button might look something like this:

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")} 

sforce.apex.execute('MyClass','MyMethod'); 
window.location.reload();

And the controller might look something like this:

global class MyClass {
    public static void MyMethod() {
        doMyMethod();
    }

    private static void doMyMethod() {
        // Do something
    }
}

In that controller you could look to creating the record, redirect the user to the created record and then when it's submitted, capture that DateTime when it was submitted, a formula field might do this in the Page Layout itself. The CreatedDate in this instance would be earlier than the DateTime submitted and you could get the difference this way.

This could get messy though if Users go to create a record, only to leave it and not come back to it. In which case you'd probably want to write a Trigger that would delete certain records if they're missing key pieces of information.

Apologies if I've completely misread what you're after but hopefully this will give you some ideas as to how to do this.

1

One way that I could think of is overriding the "New" button for your Custom Object. Have a new datetime field that would hold the time at which the form opens. Put this field on the Form ( standard layout ) and get its id by viewing its source.

You would need to write a simple VF page and controller to pre-populate this field and redirect to the standard layout. The users wont see the VF page. It is just for pre-populating and redirection.

VF Page

<apex:page standardController="Account" extensions="AccountOverrideController" action="{!setAndRedirect}">
  <h1>Nothing to be seen here</h1>
</apex:page>

Controller

public class AccountOverrideController {

    public Account acc{get;set;}

    public AccountOverrideController(ApexPages.StandardController controller) {
        acc = (Account)controller.getRecord();
    }

    public PageReference setAndRedirect(){

        PageReference pg =  new PageReference('/001/e?RecordType='+acc.RecordTypeId+'&nooverride=1&00N9000000E8zGy='+System.now().format());
        return pg;

    }

}

Replace the id '00N9000000E8zGy' with what you obtained by inspecting the source.

So when the user opens the record the time is saved into this field and you can compare this with the created date and find out how long it took for him.

You must log in to answer this question.

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