You need to sign in to do that
Don't have an account?
Again Again
To choose APEX or SControl?
Hi,
I'm looking to implement a new page/view/integrated report and I'm not sure whether I should be going with an S-Control or Apex Code. I have limited experience with S-Controls as they were before the winter release (have written some to display data from different recordsets and update this).
In theory, I could create this page as a back-end report (have some replication in place and user SQL reporting services), but I don't want to burden my server with replicating the different objects at a very high frequency. This is why I'd like to create this solution inside Salesforce.
The scenario: need to display selected data for a custom object related to a case. Basically, I have case, account, check requests (related to case) and complaints (related to case). For a given check request, I will want to show some case info, some account info, the complaints for the parent case, and a list of the attachments for the parent case.
I think I can do this with an s-control - a bunch of queries and displays. However, I think the s-control will be a little slow. My other s-controls got slow if I was pulling 3 or 4 different queries. Also not sure if I'll run into any problems with joins.
Not having done any APEX coding, I'm not sure if it's intended for a problem like this. Can it do the same thing as the s-control would, but faster?
I'll appreciate any guidance you can give.
Thanks
Rozanne
https://na4.salesforce.com/servlet/servlet.Integration?lid=01r500000009Upd&ic=1
Was linked to from AJAX Tools 0.8.4 - not sure where it is in site navigation setup, but I'll take what I can get :-)
I've made a little progress (very little!) based on the docs I've been working with (mostly the AJAX toolkit dev guide and the "Relationship Queries" chapter of the API doc.
So, I have the following snippet:
select cr.Id, cr.Taxes__c, Case__r.Subject, Case__r.Status FROM Check_Request__c cr Limit 20
and this returns a checkrequest record, and what seems like a related list for the case object. The above query runs correctly.
I now output the values, but can't figure out the syntax to show the (parent Case)'s subject or status.
for (var i = 0; i < records.length; i++) {
var checkrequest = records[i]; // no error
var parentcase = checkrequests__r; // no error thrown, but I'm not actually sure
var subject = parentcase(0).Subject; // a guess - assuming the case__r relationship is being returned as another array, maybe i need to loop through these also??
//somehow need to get the nested case values.
//String fname = bbb.getFirstname(); - ?? doesn't work
output += checkrequest.Id + "<br> " + subject; // id displays, but subject says [object error] on the display (at least no javascript error)
}
There is another example, where they'll use syntax like this:
Contact contact = (Contact)qr.getRecords(i) but this is used with a binding and whathaveyou, which the other example set I'm following doesn't have.
Could someone please help me out of my murky misery??
Hurray ... a little more
var it = new sforce.QueryResultIterator(queryResult);
while(it.hasNext())
{
var record = it.next();
var CaseSubject = record.Case ? record.Case.Status : null;
output += "<LI>" + record.Taxes__c + " " + CaseSubject;
}
Only ... both display null instead of the value.
select cr.Id, cr.Taxes__c, Case__r.Subject, Case__r.Status FROM Check_Request__c cr Limit 20
You can access the fields like this:
var it = new sforce.QueryResultIterator(queryResult);
while(it.hasNext())
{
var record = it.next();
alert("Result " + record.Id + record.Taxes__c + record.Case__r.Subject +
record.Case__r.Status);
}
You can just alert(record) and see what all fields/child objects it got.
That's very useful, thank you! I can see that the recordset does return the value I expect, so I think it's maybe a syntax issue?
a: var ComplaintName = record.Complaint__c ? record.Complaint__c.Id : null;
b: var ComplaintName = record.Complaint__c ? Id : null;
what is the : null for?
The guide uses line (a), but in my scenario this writes out the word "null".
Extract of the recordset returned below:
{type:'Complaint__c',
Id:'a0760000000t3ukAAA',
Component_Group__c:'Transmission / Transaxle',
Complaint__r:{type:'Complaint_Causes__c',
Id:'a0F300000008Zo6EAE',
Name:'Transmission',
},
Cause__r:null,
Cause_Description__c:null,
Labor_Code__r:null,
Correction_Description__c:null,
Case__r:{type:'Case', Id:'50060000002hcs1AAA',
},
}
Component Group Transmission / Transaxle
Subcomponent Automatic Transmission
{type:'Complaint__c',
Id:'a0760000000tFIZAA2',
Component_Group__c:'Transmission / Transaxle',
Sub_Component__c:'Automatic Transmission',
Complaint__r:{type:'Complaint_Causes__c',
Id:'a0F300000008Zo6EAE', Name:'Transmission',
},
Cause__r:null,
Cause_Description__c:'Vehicle moved erratically',
Labor_Code__r:{type:'Labor_Code__c',
Id:'a0630000000KaoyAAC',
Name:'X1300',
Description__c:'Description of Labor Code',
},
Correction_Description__c:'Problem.',
Case__r:{type:'Case', Id:'50060000002hcs1AAA', }, }
{type:'Complaint__c',
Complaint__r:{type:'Complaint_Causes__c',Id:'a0760000000t3ukAAA',
Component_Group__c:'Transmission / Transaxle',
Id:'a0F300000008Zo6EAE',
Name:'Transmission',
}
This tells me that the record is of type Complaint__c.
So try this:
var ComplaintName = record.Complaint__r ? record.Complaint__r.Name : null;
Wonderful, thank you! You've made my day!
When a field is legitimately empty and the display comes through as null ... is there a standard way to convert it to a blank string or does one run it through one's own stringreplace function?
That works. You've made my day!
When legit "null" values are returned - should one create a new string object for each variable to use the s.replace("xx","yy"); function, or is there a way to replace the null strings more "automatically"?
Thanks so much!
always return non-null string, something like:
function toNonNullString(str) {
return str ? str : "";
}
can be used like:
var name = toNonNullString(record.Name);