function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JimmmyJimmmy 

Dynamically Query Merge fields?

Is there a way to Dynamically Query Merge fields that would include all custom merge fields that were set up? this would be for use in an S-Control.
JimmmyJimmmy
After some digging I have found an answer.
use sforce.connection.describeSObject to get all the fields and then use SOQL to query for the values. 

var result = sforce.connection.describeSObject("Lead");
var fields = result.getArray("fields");

for (var i=0; i<fields.length; i++)
{
    var field = fields[i];
    var result = sforce.connection.query("Select "+field.name+" from Lead where ID = '{!Lead.Id}'", {onSuccess : success, onFailure : failure});
}
    function success(result)
    {
              var values = result.getArray("records");
              var foo = values[0];
              var index = 0;
              var Name = "";
              var Value = "";

           for (property in foo)
                 { if (index === 2)
                         {
                           Name = property;
                           Value = foo[property];
                            alert(Name + " : " + Value);
                         }
                          index++;
                  }
}

function failure(result)
{
  alert("ERROR : " +result);
}