Salesforce Apex invoke Save on Edit page using PageReference - salesforce

The functionality I have written works, this is for a test method.
In apex test code, I create a StandardController then a controller extension and invoke a method on that controller extension which returns a PageReference to a custom object's standard edit page. I want to change field values on that edit page and invoke the Save method/button, is this possible and how?
In advance, thanks.

No, you cannot change values in a standard edit screen from within a test method, nor do you need to. The correct way to test logic that is executed after saving on a standard edit screen is to construct an instance of a new record, populate the fields, and insert it into the database.

Related

How to call Data Editor from Code, C1 CMS?

Under definition tree, I can attach event to open Data Editor for certain element.
However, I have no idea how to trigger the workflow to open the Editor for a given id.
I have a custom action URL which point to a custom ASPX (List of businesses about 50,000) in the console.
Now I want to trigger call the default data editor from the custom ASPX. Is that possible.
Yes you can. There is a few steps you need to take, but then you can basically mimic all console behaviors from your own aspx-page.
First of all you need to include the necessary C1 Console javascript frameworks on your page. Do that by calling ScriptLoader.Render("sub") and write the result on your page. You would also need to include this javascript on your page https://github.com/burningice2866/CompositeC1Contrib/blob/master/Teasers/Package/content/Composite/InstalledPackages/CompositeC1Contrib.Teasers/teaserConsoleFunctions.js - its some wrapper methods which are able to construct the javascript objects needed to call C1's webservice methods.
When that is setup you can trigger opening a Edit Workflow by calling the executeAction javascript method via a link containing the necessary ActionToken and EntityToken like this https://github.com/burningice2866/CompositeC1Contrib/blob/master/Teasers/Web/UI/TeaserHtmlHelper.cs#L65.
Its important to understand that everything in the C1 Console in based on these tokens. You don't edit something based on its id but always based on the EntityToken the something is represented by.
And what you want to do, whether its edit something or delete it, that thing you want to do is represented by an ActionToken. So to be able to edit something, you need an EntityToken for that something and a ActionToken for the Data Editor.

Custom Save button on salesforce contract object

I have been trying to use custom save button on contract object . where it should function the standard save functionality. I have tried by using java script where in script i have mentioned end point url . but unable to function clearly.
Any perfect code for it.
you could go to object page and then buttons area. in here you can create a button to point it to anywhere you want.
then go to your layout and replace save button with the new one.

Zend Form Object as a string

I have a system which has certain page content stored in the database. Within this text we have the ability to add in custom scripts such as {WIDGET_FORM} which replaces the text with the content of a class named app_resource_widget_form. Up until now this has worked but the form needs to be created by Zend Form. Unfortunately the function which creates this requires a string(html) to be returned as so far i can only return the zend form object. Does any one know if what i am trying to do is possible. At some point the form must get created as html, is there a way to manually call this and then use that?
Thanks in advance
Zend_Form has a __toString() method, so:
$html = str_replace('{WIDGET_FORM}', $form->__toString(), $html);

Recreate a form in CakePHP 1.3 from $this->data?

I've got a Cake application with a reports query interface, where the admin user can filter the data by various inputs in a form and the results are then displayed on the screen. I am looking for the simplest way to add a button which allows the user to download the results of this same query as CSV.
I'm sure I can create one for myself if I have to, but is there already a way to regenerate any given form based on $this->data? That way, I can just add .csv to the form action and use RequestHandler to choose the right output format.
[here take a look at the following...
instead of finding the data from Db you can simply pass $this->data to it.
take a look at follo
Exporting data to CSV the CakePHP way
I guess you have to replicate the function on your controller, one for generating the results on screen and another same function intended for csv, but on the function for csv it must have parameters which are similar to the values of $this->data. Use javascript to redirect on the function for csv.

Want to display results of a callout

When a user 'Saves' a Contact (for example), whether it's new or just updated, I need to:
Do an external callout using one of the Contact field values as a lookup
Display the results of the callout, so the user can make a selection
Update the Contact based on the user's selection display the updated Contact
I have found two aproaches, but have reached a point in both that I need to resolve.
Trigger Based Method
In the 'after' trigger pass the lookup string to a callback.
Update the Contact with the selection
Issues
How do you pass the lookup string or results to a visualforce page to display the lookup results?
When the user makes the selection and the update has been done, how do I move back to the updated contact?
Override Base Method
I found a discussion here that seems to suggests using overriding & redirection to someone asking about 'Edit'. I think this could also be done with the 'Save' button.
Issue
This is meant to be a deployable sollution, so I think that the override has to be set in code (I'm using the IDE) and not via Setup (or am I wrong?). I can't find out if this is possible or how to do it
Sorry for detailed question. Didn't want to just ask the wrong question (i.e. assume I know the best approach).
Thanks...
For the trigger-based method, you cannot change the built-in Save functionality, but (per your second solution) you can override the Edit button and recreate the Edit page with Visualforce, which would give you full control over the Save button and how you handle the callout and redirecting.
The release notes for Spring '10 indicate that standard-button overrides are now available for packaging, as they can be created through the Metadata API.

Resources