Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6607555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:30:57+00:00 2026-05-25T19:30:57+00:00

I feel like I must be doing this wrong. I’ve got a function that

  • 0

I feel like I must be doing this wrong. I’ve got a function that is supposed to construct a query based on an API’s description of available fields. Here’s what I’ve got:

var query_fields = getQueryFieldsFor(sobject_name);
// Need query fields for the next statement, which actually does the query

public function getQueryFieldsFor(sObject:String):String{
    //helper function to get queryfields for given sobject
    var queryFields:String = '';

    app.connection.describeSObject(sObject,
        new mx.rpc.Responder(
            function(result:DescribeSObjectResult):void{
                var returnFields:String = '';
                for ( var field:Field in result.fields ){
                    if(field.active){
                        returnFields.concat(field.name+',')
                    }
                }
             returnFields.slice(0, returnFields.length-1); //remove last comma
             queryFields = returnFields;
        }, function(error):void{
            Alert.show('error in getQueryFieldsFor function');
        })
     );

     return queryFields;
}

I know this doesn’t work, and I think I understand why. However, I keep running into this type of issue and I believe I’m just thinking about it/designing it wrong. So what’s a better pattern here? Would really appreciate any insight on this. Many thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:30:58+00:00Added an answer on May 25, 2026 at 7:30 pm

    It would be better to externalize your functions and execute your next line of code after the fact:

    public function getQueryFieldsFor(sObject:String):String
    {
        var responder:Responder = new Responder( onResult, onFault);
        app.connection.describeSObject(sObject, responder);
    }
    
    private function onResult(result:DescribeSObjectResult):void
    {
            var returnFields:String = '';
            for ( var field:Field in result.fields ){
                if(field.active){
                    returnFields.concat(field.name+',')
                }
            }
         returnFields.slice(0, returnFields.length-1); //remove last comma
         queryFields = returnFields;
    }
    

    Your main problem though is not the code, but a lack of thinking asynchronously. You cannot have a function called “getQueryFields” that will return it instantly. What you want to do is think in the request/response way. You’re trying to get some data, a request is made to a service, gets the data back, updates a property which is then binded to a view which gets redrawn. This is the proper way to do any webapp.

    It might be beneficial for you to also look at application frameworks like RobotLegs and Parsley since it helps you manage these situations. Parsley also has a task library which lets you perform several asynchronous task one after another.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like I must be missing something completely obvious, but I don't see
I'm at a point in my development learning where I feel like I must
I feel like I should know this, but I haven't been able to figure
I feel like this is a stupid question because it seems like common sense
I feel like this is a dumb question and I'm missing something, but I
I feel silly asking this, I must be missing something obvious. My javascript looks
UPDATED: Added some sample code to help clarify. Hi, Feel like this shouldn't be
When I first learned Python, I got used to doing this: print text, lineNumber,
I feel like this might be a crazy question, and if anyone has a
I feel like there must be a much better way of expressing the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.