function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SkiesnPiesSkiesnPies 

Diverting To New Page On Save

Hi, I have a requirement to intercept the save event on a standard object (Task in this case) and based on criteria in  the task, possibly divert to a VF page. 

 

On existing records (ie. when the users clicks the EDIT button), this is straightforward with the following steps :

  • Customise the EDIT button to add a &saveURL to the URL when opening the task in editmode, the SaveURL will divert on save to VFpage1 and pass VFPage1 the parameter of the Task that is being edited.
  • VFPage1's controller can then lookup the task using the supplied ID and decide based on the task values if it should divert to VFPage2 or just go back to the saved task.  

This works nicely, however : 

 

Problem is : 

How to replicate this functionality for NEW task records. At the time the task is created , I can't pass the ID of the record to VFPage1 as the task at this stage doesn't have an ID, so VFPage1 is unable to lookup the task that just got saved. How to get my new ID into some code somewhere to make this divert decision?

 

I could do it in Javascript if I could make the task save to a "ready only" version of itself when it was saved, but again, the &SAVEURL to make it do this would need the ID of the task which doesn't yet exist.

 

Is there any way to  code this ? I just want to be able to make a decision in either VF, Apex or Javascript as to where to go when my new task saves based on values in the Task record. 

 

Thanks in advance......

 

 

 

Shailesh DeshpandeShailesh Deshpande
You can create a vf page with std controller as task and also let this page have extension. Then create a custom button called "save" and the content type for this button as the vf page you created. on click of save you could call an action method and determine whther the action was in done from the edit tasks screen or from New tasks screen.based on this, you can explicitly fire an update or insert statement and then use the pagereference class to redirect user to whichever page you want. In either case you will now have the id of the task.

To identify whther it was in edit mode or new task screen, you need to get the url of the page using getURL() METHOD. In case of edit mode the url will have 00T/e present in it.
SkiesnPiesSkiesnPies

Hi Shallesh, thanks for the reply do you mean entirely replace the task screen with a custom edit screen and controller? I presume so as otherwise how to get my VF button on the standard screen when its in edit mode? Trying to avoid that if possible but if its the only way....

 

I am starting to clutch at straws now, but wondering if a bit of JS could intercept the onsubmit somehow and switch the SAVEURL value if it found the field values to be satisfactory - but this would depend on being able to change the SaveURL before the submit was actioned...

 

Any alternatives v.welcome.....

SkiesnPiesSkiesnPies

Actually, I don't think the JS solution would work either as that relies on replacing the entire page with a custom VF page I think - otherwise how to get the JS onto the standard task screen in edit mode.......

 

 

Shailesh DeshpandeShailesh Deshpande
Oops..sorry..how could I forget that you cant add the custome button in the edit layout. Sorry for misleading you.
SkiesnPiesSkiesnPies

Hey, I appreciate your efforts Shailesh, am starting to draw a blank though - may need to COMPLETELY re-think the approach on this one and change the order of events in the business process I think. Thanks for responding though. 

 

Anyone else any thoughts before I tear up my plans ?   :-)