0

So i'm trying to do multiple query in one function javascript. Below my example code:

function getopp(){
    var soql;
    var soqlopp;
    var records;
    var recordsopp;
    var recordacc;
    sforce.connection.sessionId = "{!$Api.Session_ID}";
    soql = sforce.connection.query('Select Id from Account limit 1');
    records = soql.getArray("records");
    alert('account size : '+records.length);
    if(records.length > 0){
        recordacc = records[0];
        alert('record account id : '+recordacc.Id);
        soqlopp = sforce.connection.query('Select id from Opportunity where AccountId in (\'' +recordacc.Id+ '\') limit 1');
        recordsopp = soqlopp.getArray("recordsopp");
        alert('opp size : '+recordsopp.length);
    }
}

So result for this function is account ID found, but when i try to query opportunity the size always 0, i've tried to remove where clause but result still 0. Is there any way to do multiple query in single javascript inside visualforce?

Thanks

3
  • Have you tried recordsopp = soqlopp.getArray("records"); Apr 28, 2020 at 9:08
  • @SergioAlcocer yes and its worked perfectly, thanks for your feedback :)
    – Enriko
    Apr 28, 2020 at 9:50
  • FYI, you should use apex:remoteObjects to save API calls.
    – sfdcfox
    Apr 28, 2020 at 9:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.