Account Name :
Thanks Pooja", "answerCount": 1, "upvoteCount": 0, "datePublished": "2017-02-03T03:45:37.000Z", "author": { "@type": "Person", "name": "pooja biswas", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000CzBaTQAV", "affiliation": { "@type": "Organization", "name": "--" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "hi, try using this when you get result.  \"result.getArray(“records”);\". You get associative array. You can not just use result.Id etc. try to debug in console.log(); and let me know if it helps.  ", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4VFrSAN", "datePublished": "2017-02-04T18:10:58.000Z", "author": { "@type": "Person", "name": "Dattaraj Deshmukh", "url": "https://trailblazers.salesforce.com/profileView?u=0053000000AKWdmAAH", "affiliation": { "@type": "Organization", "name": "Transforme" } } } ] } }
Skip to main content
pooja biswas が「#Apex」で質問
Hello

I am trying to understand how to call a webservic eusing javascript remoting.

I have attached the code but after trying a lot it is not gving the desired result.

any help will be greatly appreciated.

global class remotingexample

{

public String accountName { get; set; }

public static Account account { get; set; }

public remotingexample() { }

@RemoteAction

webservice static Account getAccount(String accountName)

{

account = [select id, name from Account where name=:accountName ];

return account;

}

}

<apex:page controller="remotingexample">

<script type="text/javascript">

function getAccountJS()

{

var accountNameJS = document.getElementById('accName').value;

sample.getAccount( accountNameJS,

function(result, event)

{

if (event.status)

{

// demonstrates how to get ID for HTML and Visualforce tags

document.getElementById("{!$Component.theBlock.thePageBlockSection.theFirstItem.accId}").innerHTML = result.Id;

document.getElementById("{!$Component.theBlock.thePageBlockSection.theSecondItem.accNam}").innerHTML = result.Name;

}

else if (event.type === 'exception')

{

document.getElementById("errors-js").innerHTML = event.message;

} else

{

document.getElementById("errors-js").innerHTML = event.message;

}

}, {escape:true});

}

</script>

Account Name :<input id="accName" type="text" />

<button onclick="getAccountJS()">Get Account</button>

<div id="errors-js"> </div>

<apex:pageBlock id="theBlock">

<apex:pageBlockSection id="thePageBlockSection" columns="2">

<apex:pageBlockSectionItem id="theFirstItem">

<apex:outputText id="accId"/>

</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem id="theSecondItem" >

<apex:outputText id="accNam" />

</apex:pageBlockSectionItem>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:page>

Thanks

Pooja
1 件の回答
  1. 2017年2月4日 18:10
    hi,

    try using this when you get result.  "result.getArray(“records”);". You get associative array. You can not just use result.Id etc.

    try to debug in console.log(); and let me know if it helps.

     
0/9000