You need to sign in to do that
Don't have an account?
nimdhar
Calling a web method from a visual force page javascript function
Hi,
I am calling a web method from a javascript function in a visual force page. But that function is not getting called. Below is the code
This is in my visual force page calling the javascript function
<apex:outputlink onclick="setLeadLocation('{!$CurrentPageReference.parameters.leadid}','{!location.id}');"> Attach </apex:outputlink>
This is my javascript function which calls the webmethod
function setLeadLocation(leadid,locationid)
{
sforce.apex.execute('LeadServices','assignLocationToLead', {leadId:leadid,locationId:locationid});
}
This is my web method
global class LeadServices
{
Webservice static void assignLocationToLead(ID leadId, ID locationId) {
Lead lead = [select Id from Lead where Id=:leadId];
lead.Location__c = locationId;
update lead;
return;
}
Can anyone tell is this not possible from a visual force page?
Thanks,
Nimdhar
I am calling a web method from a javascript function in a visual force page. But that function is not getting called. Below is the code
This is in my visual force page calling the javascript function
<apex:outputlink onclick="setLeadLocation('{!$CurrentPageReference.parameters.leadid}','{!location.id}');"> Attach </apex:outputlink>
This is my javascript function which calls the webmethod
function setLeadLocation(leadid,locationid)
{
sforce.apex.execute('LeadServices','assignLocationToLead', {leadId:leadid,locationId:locationid});
}
This is my web method
global class LeadServices
{
Webservice static void assignLocationToLead(ID leadId, ID locationId) {
Lead lead = [select Id from Lead where Id=:leadId];
lead.Location__c = locationId;
update lead;
return;
}
Can anyone tell is this not possible from a visual force page?
Thanks,
Nimdhar
Message Edited by dchasman on 04-30-2008 12:19 PM
Yes I tried the same with commandLink having an action method as follows
<apex:pageblocksection title="Locations" id="locationresults">
<apex:pageblocklist value="{!locationresults}" var="location" rendered="{!NOT(ISNULL(locationresults))}">
<apex:column headerValue="Name">
<apex:outputlink value="/{!location.id}">{!location.name}</apex:outputlink>
</apex:column>
<apex:column value="{!location.Address__c}" />
<apex:column value="{!location.City__c}" />
<apex:column value="{!location.State__c}" />
<apex:column value="{!location.ZipCode__c}" />
<apex:column>
<apex:commandLink value="Attach" action="{!attach}" oncomplete="closewindow()">
<apex:param assignTo="{!locationid}" value="{!location.id}"/>
</apex:commandLink>
</apex:column>
</apex:pageblocklist>
</apex:pageblocksection>
Message Edited by dchasman on 04-30-2008 01:43 PM
<apex:column>
<apex:commandLink value="Attach" action="{!attach}" oncomplete="closewindow()">
<apex:param name="locationId" value="{!location.id}"/>
</apex:commandLink>
</apex:column>
where location is an apex class (not sure if it already is) that wraps your sobject and adds in the attach() behavior...
Even better - we typically bind directly to an action method on the object in the list itself, e.g.:
<apex:column>
<apex:commandLink value="Attach" action="{!location.attach}" oncomplete="closewindow()"/>
</apex:column>
where location is an apex class (not sure if it already is) that wraps your sobject and adds in the attach() behavior...
How do you access the parameter id in the attach method? Can you please explain it?
Thanks,
Nimdhar