anusha(salesforce developer)

Monday, 12 December 2016

Create a dynamic soql query using ajax to fetch all the account records whose industry is matching with input value and display the account names

Create a dynamic soql query using ajax to fetch all the account records  whose industry is matching with input value and display the account names 

<apex:page id="page">
    <script src="/soap/ajax/36.0/connection.js" type="text/javascript">
    </script>
    <script>
    function callme(){
    sforce.connection.sessionId='{!$API.session_Id}';
            var myIndustry=document.getElementById('page:fm:myIndustry').value;
        var query='select name ,industry from Account where industry=\''+myIndustry+'\'';
    var queryResult=sforce.connection.query(query);
    var records=queryResult.getArray('records');
    var result='';
    for(var i=0;i<records.length;i++){
            result=result+'<br/>'+records[i].Name;
        }
           document.getElementById('page:fm:res').innerHTML=result;
        }         
    </script>
    <apex:form id="fm">
        <apex:inputText id="myIndustry" />
    <apex:commandButton  value="Ajax Call" oncomplete="callme()"/>
        <apex:outputLabel id="res" />
    </apex:form>
</apex:page>

No comments:

Post a Comment