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>

BatchApexExam

Global class BatchApexExam implements database.batchable<Sobject>
{


    global database.querylocator start(database.batchablecontext bc){
            
         string query='select id, description from account';
         
        return database.getquerylocator(query);
    }
    
    global void execute(database.batchablecontext bc, list<account> acclist){
    
            for(account a: acclist){
                
                a.description='Batchapex';
            }
            
            update acclist;
    }
    global void finish(database.batchablecontext bc){
    
    }
    
}