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
alexannnicalexannnic 

Help! Visualforce equivalent of S-Controls

[Preface: as of today, all of our organizations' S-Controls which used 'http://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js' do not work! This means that we must convert all of our S-controls procedures (about 20) to APEX during this weekend! Why did this happen? Without a warning? Note that we are not the only ones. See here]

 

Could you please help on the following matters?

 

I have a link in Accounts, which runs an S-control that creates a new Opportunity with some data prefilled. How can I create this in APEX-Visualforce? Create a custom link with on-click Javascript? How can I create an APEX controller + Visualforce page that:

1) gets some values from the current Account page? (old way: var AccountName = "{!Account.Name}";)

2) creates a new Opportunity object and fills in some fields

3) Saves the new Opp and redirects the browser to the new Opp page?

 

Thank you for your help!

Alex

dchasmandchasman
I have alerted the owners of the ajax toolkit to this issue - not a visualforce related issue.
DevAngelDevAngel

Hi Alex,

 

The version of the Ajax toolkit you are using was never a supported product and we have had a supported version out for a couple of years now.

 

Having said that, I realize you need some remedy.  Depending on what your code is doing, it should not be too hard to convert your s-controls to the newest, supported version of the toolkit.  I don't think we would be able to get the old version up before the end of the weekend, so I will try to get you copy of it so that you can mod your s-controls to pull the js from a static resource or, God forbid, a document.

 

Regards

mtbclimbermtbclimber

FYI, here's the Visualforce way to accomplish this...

 

Apex Class:

 

public with sharing class oppfromAccountExt {

Account account;
public oppfromAccountExt(ApexPages.StandardController controller) {
account = (Account) controller.getRecord();
}

public PageReference createOpp() {
Opportunity opp = new Opportunity(AccountId = account.id, Name = account.name + ' - deal', CloseDate = Date.today(), StageName = 'Prospecting');

try {
database.insert(opp);
} catch (System.DMLException e) {
ApexPages.addMessages(e);
return null;
}

return new ApexPages.StandardController(opp).view();
}

}

 

 Visualforce Page:

 

 

<apex:page standardController="Account" extensions="oppfromAccountExt" action="{!createOpp}">
<apex:pageMessages />
<apex:outputPanel rendered="false">
<!-- put expressions to fields needed in the controller here. This eliminates the need to re-query
for the same account in the extension. -->
{!account.name}
</apex:outPutPanel>
</apex:page>

 

Message Edited by mtbclimber on 06-26-2009 08:06 AM
alexannnicalexannnic

Thank you for your replies

 

@ DevAngel: It would be very nice if I could have even a temporary javascript equivalent of the old 3.3 AJAX Toolkit, at least until I firure out a way to convert all of my S-controls.

[Some of them are quite complicated. I had an S-Control (screenshot) that opened a new window, which allowed users to enter up to 15 Product Codes to an Opportunity easily. As users typed the first letters of the ProductCode, an AJAX call was made to Salesforce querying the Product's description and price, and dynamically filling in the dropdown box (combining the Dojo Javascript Toolkit) Imagine porting that to APEX-Visualforce - seems too hard for me at the moment]

 

 


@mtbclimber: Thank you for the sample. How can I add this page to Accounts Page Layout? At the moment, the new Opp is created when the user clicks on a custom link placed on Accounts page layout, i.e. (1) user clicks on custom link, (work is done on the background), then (2) user's browser is redirected on new Opp page. I tried creating a custom link with 'Display in new Window' behaviour, and 'Visualforce page' Content Source, but then the Content dropdown box appears empty (even though I've created a sample Visualforce page).

Once again, thank you for your help during these difficult times for us!

Kind Regards,

 

Alex

 

PS: I still cannot understand why the Javascript toolkit was taken down! No space? To force us use the APEX code? The latter being a good reason, however we should have received at least a two week notice for this, or tech guys should have checked if there were organizations still using it. Yesterday, our sales team had to stay up to four hours late to hand in *handwritten* orders to our production department because the S-controls would not work. And our company's production department uses also some process-critical S-Controls. Alas, I have a big weekend in front of me.

elyb527elyb527
I am confused.  My s-controls still work.  I know they are doing away with them but they promised that all current s-controls wold continue to work.  You should contact SF!
DevAngelDevAngel

You can use the Ajax toolkit in Visualforce (or any other Javascript library for that matter).  VF supports all the same HTML that scontrols do.  This means (assuming that you have a reference to the old toolkit) that you could essentially copy the source from your scontrol and paste it into a VF page between the <apex:page> tags.  The custom link on the Account page could still be onclick javascript, but the js would be document.location.href = "[Your VF Page]".

 

I would happily send the js source to you for the old toolkit.  The fact will still remain that it is unsupported, slower than the newer version, leaks memory due to closure issues and won't be updated as the platform evolves.  Hopefully these are good reasons to invest the effort into swapping.  

 

Cheers

elyb527elyb527
I understand that we should convery s-controls to VF pages but I was confused as to the urgency that was denoted in the messsage. 
mtbclimbermtbclimber

There was a technical issue that prevented salesforce from serving this file.  This was by no means intentional and it has been resolved but it does serve as a good reminder that this version of the AJAX toolkit is not supported. 

 

Generally speaking you should not use onclick javascript when the point is always to redirect to another page. Using the example above you can create a button of type Visualforce which also establishes a dependency between the button and the page that will prevent the page from being accidentally deleted as long as the button exists and the button will continue to function even if the page is renamed. Both of these are type of changes that would break the onclick JS approach.

Message Edited by mtbclimber on 06-27-2009 09:18 AM
jasonmuldoonjasonmuldoon
I am using custom s-controls to embedd a mashup in the salesforce crm. In the s-controls I access two parameters account.id and account.name({!Account.Id} and {!Account.Name}). The s-control returns an appropriate value for the above two parameters and using these i launch the mashup in the CRM. Migrating to VisualForce layout i found that the above two parameters are empty because of which I am not able to launch the mashup for the required account. But when i changed the mashup iframe from the s-control that i was using to a VF page I got the above mentioned parameters and was able to launch the mashup. Is there any way to get the account id and name from the s-control itself.