+ Start a Discussion
yespeeyespee 

calling VF page from S-Control

Hi All,
I need to override default New lead creation using a wizard created using visual force. However I came to know from Salesforce support I cannot override 'New' button of leads using a custom controller. So I am planning to use an S-control to over ride New button which in turn calls a Visual force page. However I am not sure if this can be done. I would appreciate any kinds inputs. Thanks.
dchasmandchasman
While what Support told you is technically correct it is only part of the story and has pushed you in a totally incorrect direction. The correct approach is to use a VF page that uses the standard controller for Lead and add in your logic using a custom controller extension instead of a custom controller.

Scontrols are a deprecated technology and at this point you should stop if you find yourself spending any effort writing new scontrols (or even extending existing ones).
Chirag MehtaChirag Mehta
Following is the excerpt from Apex Guide .......

Apex in AJAX

The AJAX toolkit includes built-in support for invoking Apex through anonymous blocks or public webService methods.
To do so, include the following lines in your AJAX code:
<script src="/soap/ajax/14.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/14.0/apex.js" type="text/javascript"></script>

Note: For AJAX buttons, use the alternate forms of these includes.To invoke Apex, use one of the following two methods:

• Execute anonymously via sforce.apex.executeAnonymous (script). This method returns a result similar to the
API's result type, but as a JavaScript structure.

• Use a class WSDL
. For example, you can call the following Apex class:
global class myClass {
webService static Id makeContact(String lastName, Account a) {
Contact c = new Contact(LastName = lastName, AccountId = a.Id);
return c.id;
}
}
By using the following JavaScript code:
var account = sforce.sObject("Account");
var id = sforce.apex.execute("myClass","makeContact",{lastName:"Smith",a:account});

The execute method takes primitive data types, sObjects, and lists of primitives or sObjects.

To call a webService method with no parameters, use {} as the third parameter for sforce.apex.execute. For example,
to call the following Apex class:

global class myClass{
webService static String getContextUserName() {
return UserInfo.getFirstName();
}
}

Use the following JavaScript code:
var contextUser = sforce.apex.execute("myClass", "getContextUserName", {});
Note: If a namespace has been defined for your organization, you must include it in the JavaScript code when you
invoke the class. For example, to call the above class, the JavaScript code from above would be rewritten as follows:
var contextUser = sforce.apex.execute("myNamespace.myClass", "getContextUserName",{});

Both examples result in native JavaScript values that represent the return type of the methods. Use the following line to display a popup window with debugging information:

sforce.debug.trace=true;
yespeeyespee
Thanks for putting me into right track.
I think I can work this out using Controller Extension.