You need to sign in to do that
Don't have an account?
Naishadh
Pass sobject from javascript to component
Hi,
I want to pass opportunity sobject from javascript method to component class. I am able to pass string value but not able to pass object.
Please help.
Page code :-
<apex:page controller="testController">
<apex:includeScript id="connection" value="/soap/ajax/15.0/connection.js"/>
<apex:form >
<!-- Define the JavaScript function sayHello-->
<apex:actionFunction name="sayHello" action="{!sayHello}"
rerender="out" />
<apex:outputPanel id="out">
<apex:outputText value="Hello "/>
<apex:inputText value="{!username}"/>
<apex:actionStatus startText="requesting..." id="myStatus">
<apex:facet name="stop">{!username}</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
<p>
<apex:outputText value="Clicked? {!state}" />
<apex:inputText value="{!Opportunity}" id="showstate"/>
</p>
</apex:form>
<!-- Call the sayHello JavaScript function using a script element-->
<script>
//window.setTimeout(sayHello,2000);
function testJS() {
var oppr = new sforce.SObject("Opportunity");
oppr.set("Id","123456789");
alert(oppr);
methodOneInJavascript('test',oppr);
}
</script>
<!-- Add the onclick event listener to a panel.
When clicked, the panel triggers
the methodOneInJavascript actionFunction with a param -->
<apex:outputPanel onclick="testJS()" styleClass="btn">
Click Me
</apex:outputPanel>
<apex:form >
<apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="showstate" >
<apex:param name="firstParam" assignTo="{!state}" value="" />
<apex:param name="secondParam" assignTo="{!data}" value="" />
</apex:actionFunction>
</apex:form>
</apex:page>
Component Code
public class testController{
SObject opp;
List<String> data;
public void setOpportunity(SObject s) {
System.debug(s);
opp = s;
}
public String year {get;set;}
public void setData(String[] data) {
this.data = data;
}
public String[] getData() {
return data;
}
public SObject getOpportunity() {
return opp;
}
String uname;
public String getUsername() {
return uname;
}
public void setUsername(String s) {
uname = s;
}
public PageReference sayHello() {
uname = UserInfo.getName();
return null;
}
public void setState(String n) {
state = n;
}
public String getState() {
return state;
}
public PageReference methodOne() {
System.debug('hi inside method one');
System.debug(getState());
System.debug(getOpportunity());
System.debug(getData());
return null;
}
private String state = 'no';
}
Thanks. I don't think this is possible to pass SObjects. Would a solution be to create the opp via
var oppr = new sforce.SObject("Opportunity");
oppr.set("stage","Won");
oppr.set("name","test");
..other required fields
var result = sforce.connection.create([oppr]);
then pass the Opp Id to your controller?
Sorry I can't be of more help.
I have alreay existing s-control for opportunity merge. It is just like duplicate lead or contact merge page. In my opportunity merge s-control I have to fetch user selected field value. Now I want to replace it with visual force page.
I hope u will get my point. If you have any other idea for the same please let me know.