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
devendra dhakadevendra dhaka 

Detail page custom button ..

I am not getting a proper ID

 

 

 

!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}

var newRecords = [];
 
var c = new sforce.SObject("Leave_Balance__c");

result1 = sforce.connection.query("Select Id from Leave_Balance__c where Employee_Name__c= '{!Leave_Application__c.OwnerId}' and LeaveType__c='{!Leave_Application__c.LeaveType__c}'  limit 1");          
//   LeaveType__c   is a reference { look up } to another object....    but it's giving some error , but it works fine in SOQL query in apex ??

records = result1.getArray("records");
if (records.length == 1) {
    var record = records[0];
  Id = (record.id);
alert(id);                                        

                          // here my id is some ext-gen1   ??
} else {
  alert("Something went wrong here");
}

devendra dhakadevendra dhaka

Hi Rahul,

 

Even i was using record as a variable.

 

I was generation two alert boxes      record.employee_name__c    and  record.id

 

record.employee_name__c    is providing correct value { an ID as it is a reference field }

 

but record.id  is giving   ext -gen1

 

I also changed the variable name as u suggested, But still facing the same issue ...

Rahul SharmaRahul Sharma

Problem is with this piece of code:

 

var record = records[0];
Id = (record.id);
alert(id);

 Change it to:

 

var record = records[0];
var laId = (record.Id);
alert(laId);

 Even if you alert : alert(id); it will display ext -gen1(id might be a global variable holding ext -gen1).

devendra dhakadevendra dhaka

ID is not an global variable. I am fetching it from a saleforce record of LEAVE_BALANCE__C.

 

it must be 15 digit ID as its retruning value in the SOQL query exectuion.

Rahul SharmaRahul Sharma

id retrieves HTML Id in your DOM, so change the variable name which you are using to collect id.

 

Try this:

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}

var newRecords = [];
var c = new sforce.SObject("Leave_Balance__c");

result1 = sforce.connection.query("Select Id from Leave_Balance__c where Employee_Name__c= '{!Leave_Application__c.OwnerId}' and LeaveType__c='{!Leave_Application__c.LeaveType__c}'  limit 1");          
//   LeaveType__c   is a reference { look up } to another object....    but it's giving some error , but it works fine in SOQL query in apex ??

records = result1.getArray("records");
if (records.length == 1) {
    var record = records[0];
  var laId = (record.id);
alert(laId);                                        
                          // here my id is some ext-gen1   ??
} else {
  alert("Something went wrong here");
}

 

devendra dhakadevendra dhaka

Hi Rahul,

 

I already tried that , but no luck

 

 

But I have found the solution. When i Retrieve the NAME of the record. It is giving me back the RECORD ID

 

I can solve that my problem using that, But 'm not satisfied that why is that happening.

devendra dhakadevendra dhaka
<I have attached the WSDL code for LEAVE_BALANCE
bBut there 'm not able to find ID.              Is it the solution for my problem that why 'm getting ID in NAME field ?/
element name="ActivityHistories" nillable="true" minOccurs="0" type="tns:QueryResult" />
  <element name="Attachments" nillable="true" minOccurs="0" type="tns:QueryResult" />
  <element name="CreatedBy" nillable="true" minOccurs="0" type="ens:User" />
  <element name="CreatedById" nillable="true" minOccurs="0" type="tns:ID" />
  <element name="CreatedDate" nillable="true" minOccurs="0" type="xsd:dateTime" />
  <element name="Employee_Name__c" nillable="true" minOccurs="0" type="tns:ID" />
  <element name="Employee_Name__r" nillable="true" minOccurs="0" type="ens:User" />
  <element name="Events" nillable="true" minOccurs="0" type="tns:QueryResult" />
  <element name="FeedSubscriptionsForEntity" nillable="true" minOccurs="0" type="tns:QueryResult" />
  <element name="Histories" nillable="true" minOccurs="0" type="tns:QueryResult" />
  <element name="IsDeleted" nillable="true" minOccurs="0" type="xsd:boolean" />
  <element name="LastActivityDate" nillable="true" minOccurs="0" type="xsd:date" />
  <element name="LastModifiedBy" nillable="true" minOccurs="0" type="ens:User" />
  <element name="LastModifiedById" nillable="true" minOccurs="0" type="tns:ID" />
  <element name="LastModifiedDate" nillable="true" minOccurs="0" type="xsd:dateTime" />
  <element name="LeaveType__c" nillable="true" minOccurs="0" type="tns:ID" />
  <element name="LeaveType__r" nillable="true" minOccurs="0" type="ens:LeaveType__c" />
  <element name="Leave_Credit__c" nillable="true" minOccurs="0" type="xsd:double" />
  <element name="Name" nillable="true" minOccurs="0" type="xsd:string" />
  <element name="Notes" nillable="true" minOccurs="0" type="tns:QueryResult" />
  <element name="NotesAndAttachments" nillable="true" minOccurs="0" type="tns:QueryResult" />
  <element name="OpenActivities" nillable="true" minOccurs="0" type="tns:QueryResult" />
  <element name="ProcessInstances" nillable="true" minOccurs="0" type="tns:QueryResult" />
  <element name="ProcessSteps" nillable="true" minOccurs="0" type="tns:QueryResult" />
  <element name="SystemModstamp" nillable="true" minOccurs="0" type="xsd:dateTime" />
  <element name="Tasks" nillable="true" minOccurs="0" type="tns:QueryResult" />