• Farhat Mirza
  • 0 Points
  • Member since 2011

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 9

JSON.Serialize method not returning null fields(Copied from stack exchange).

We are in big problem with this release.




I have been using JSON.Serialize method extensively in one of customer's project. Today salesforce has started rolling out Spring '13 release on sandboxes. My customer's sandbox( cs11) is not listed onhttps://trust.salesforce.com/trust/maintenance/ but still Spring '13 is available in this sandbox.


I have noticed a change that if I serialize a sObject, Json Serializer doesn't return fields with null value in json. Before Spring '13 release it was working fine.

If this was a needed change to reduce size of serialized json, Salesforce should have made this version specific change or a overloaded method to keep backward compatibility. It has broken 30%-40% of my code that I will need to rewrite.


Salesforce please undo this change.

Current output: [ { "attributes": { "type": "ABC_c", "url": "/services/data/v27.0/sobjects/ABC_c/xxxx" }, "Active__c": false, "Id": "XXXX", "Name": "ABC" }, ]

Old output: [ { "attributes": { "type": "ABC_c", "url": "/services/data/v27.0/sobjects/ABC_c/xxxx" }, "Active_c": false, "FirstName_c": null, "Id": "XXXX", "Name": "ABC" }, ]



I need to get a list of users who are having access to a given managed package.



Farhat Mirzaq



I want to access allowed profiles of Organisation wide email addresses. I am able to access is that email address is allowed to all profiles or not. Can anyone please suggest me some solution to achieve 'Allowed profiles' details.





I have a solution that can be resolved using two SOQL queries instead of one. though I think It can be done with one. if you are open to the challange, please continue...


I think I possibly found a bug in Apex. or is this by design? would be happy to be told I'm wrong and have a solution to my problem :smileyhappy:. If I am correct, the Bug is in my 5th attempted solution.


My object "Timesheet__c" is a detail object of Contact (which is master). Each contact has a field called "Employee_Reference__c" Which is a Formula(Number, Roll-up Summery from a 3rd object called "Payroll Record").


I am attempting to generate a table that would show some aggregate values from "Timesheet__c" along with the employee's reference.

This will give me a table with the following Columns [Employee Reference, Sum1, Sum2, Sum3] etc.

The problem is that Employee_Reference__c is not a groupable field, and thus a SOQL group by statement does not allow this field to be used.


I've attempted different solutions and failed:


  1. query from the parent (Contact), doesn't work since salesforce doesn't support Aggregate functions in the sub query, Agg. Functions are only  in the parent query)

  2. Query the field from the master object via the child table. I was hoping the grouping would work as the grouped field implies a unique order. No success.
Select Worker__r.Employee_Reference__c from Timesheet__c Group by Worker__c

 3. Using a formula field in the child  (Which looks up the parent Employee_Reference__c value) object and querying that. Failed miserably.

4. Copying the formula field to a non-formula field. Fails as it would need cross object workflow rule (the field update would need to be done for the parent object), which is not supported.


5. I've decided to disguise the Employee_Reference__c as an aggregate object. this Looks at the parent object and takes the MAX(). I hoped this would work as there is only one value to per line, MAX() should always return the value I want.

The query complies and runs, and looks good on the Eclipse Schema Editoer query window. However, when attempting to address this field after the query, I get the error "Save error: Invalid field MAX_Employee_Reference for SObject AggregateResult" .


Here is the SOQL Query: 

select Worker__c Worker, SUM(Standard_Pay_Taxed__c) SUM_Standard_Pay_Taxed,    														MAX(Worker__r.Employee_Reference__c) MAX_Employee_Reference,    														SUM(Holiday_Pay__c) SUM_Holiday_Pay,  															SUM(Taxed_Expenses__c ) SUM_Taxed_Expenses,     														SUM(Taxed_Deductions__c) SUM_Taxed_Deductions,															SUM(Non_Taxed_Expenses__c ) SUM_Non_Taxed_Expenses,     														SUM(Non_Taxed_Deductions__c) SUM_Non_Taxed_Deductions    														from timesheet__c where Week__r.Week_Ending__c = LAST_N_DAYS:7
Group by Worker__c

6. My solution will be to use a second SOQL, and to then use a map to align the Employee_Reference__c values. I don't like it though...


Thank you for your time.

Has any one experienced this issue with date input fields.


Date picker for a date input does not work when showHeader="false" in <apex:page>


<apex:page standardController="Account" showHeader="false">
<apex:pageBlock title="Test Date Picker when showHeader is set to False" mode="edit">
<apex:commandButton action="{!save}" value="Save"/>
<apex:pageBlockSection columns="2">
<apex:inputField value="{!account.name}"/>
<apex:inputField value="{!account.SLAExpirationDate__c}"/>


If you set showHeader to "true" then date picker works fine for date input fields.


I have tried it in IE8 and Firefox and it shows the same behaviour.





  How to create more than one pages by using Sites method. Actually i created one site in salesforce.com like my domain name is multlanguagesfg-developer-edition.ap1.force.com,  but i need to create multiple pages in this same site domain..what i do. ..please help me






  • March 09, 2011
  • Like
  • 0

Hi all,


I am having text field, in that i want to dispaly the Fiscal Year and quarter of our company which we assigned in sales force.


Right Now I want to get the current Date Fiscal Year and Quarter from the company profile object, also i want to get the Fiscal year for the specified date by the user (eg:- if the user enter's one date in the text field then i want to display the fiscal year and quarter of the date entered by the user).the fiscal year should taken from the company profile,


but i do know how to get the FY and Quarter from the company profile, please help me in this issue.


Thank you all in advance,




Hey all,

I am in the process of shifting a bunch of tools into salesforce. To do this basically I am rewritting the front ends in jQuery (and plugins) and creating Apex web services that fetch the required data and return it in JSON format to the front end components.


I want to write one component, I can pass it a query string, it returns me a JSON formatted object. However, I am not handy enough in Apex syntax to pull this off. I have a framework in place, but I don't know 2 things.


1) How do I make a query completly out of a URL variable.

2) How can I loop over all the column names returned in a query?


Below is the code I have so far, that has been the basic outline of my componts so far, but I want to stop having to make a new component for every tool. Any help is appreciated. Thank you.



public class queryToJSON { public JsonObject json {get;set;} /** invoked on an Ajax request */ public void getJson() { //There should be a parameter called QueryString in the URL. Map<string,string> params = ApexPages.currentPage().getParameters(); json = new JsonObject(); // Do SOQL query to see if there are any records ! List<Events__c> records = new List<Events__c>(); // Here I need a totally dynamic query, built from the URL query string variable. // theoretically it would look like this. // records = [params.get('queryString')]; if (!records.isEmpty()) { // Jsonify the results ! List<JSONObject.value> values = new List<JSONObject.value>(); for (Events__c c : records) { JSONObject cjson = new JSONObject(); //Now for every column in the query, I need to construct a new JSON "element" //I can do that statically by typing something like this //cjson.putOpt('"id"', new JSONObject.value(c.Id)); //That adds the id field to my JSON object. But I won't know all the columns that are //being queried for, so I am going to need to loop over all the columns returned for every row //and add them dynamically to my JSON object. values.add(new JSONObject.value(cjson)); } json.putOpt('events', new JSONObject.value(values)); } } // Returns the JSON result string public String getResult() { string jsonString = json.ValuetoString(); return jsonString; } }




When developing a Visualforce page for overiding view page for any object, one problem that creeps up is to display the History details of a record. The standard related list Component doesn't works for History.


With the help of some code from Community ( I now can't find the link to it :( ), I wrote my own code  then to display the history of an object. It mimics the standard list as far as possible.  


Heres the code. It is for the Case object but it can be used for any other object.

 1.Component Code


<apex:component controller="CaseHistoriesComponentController">
<!-- Attribute Definition -->
<apex:attribute name="CaseId" description="Salesforce Id of the Case whose Case History needs to be rendered" type="Id" required="true" assignTo="{!caseId}" />

<!-- Case History Related List -->
<apex:pageBlock title="Case History">
<apex:pageBlockTable value="{!histories}" var="History" >
<apex:column headerValue="Date" value="{!History.thedate}"/>
<apex:column headerValue="User"> <apex:outputLink value="/{!History.userId}"> {!History.who} </apex:outputLink></apex:column>
<apex:column headerValue="Action"><apex:outputText escape="false" value="{!History.action}"/></apex:column>





2. Apex Code


public class CaseHistoriesComponentController {

public Id caseId {get; set;}
public cHistories[] histories;

// Variables
public Static final Map<String, Schema.SObjectField> CaseFieldmap = Schema.SObjectType.Case.fields.getMap();
public Static final List<Schema.PicklistEntry> fieldPicklistValues = CaseHistory.Field.getDescribe().getPicklistValues();

public List<cHistories> getHistories()
list<cHistories> histories = new list<cHistories>();
String prevDate = '';
for(CaseHistory cHistory : [Select CreatedDate, CreatedBy.Name, CreatedBy.Id, Field, NewValue, OldValue from CaseHistory where CaseId = :caseId order by CreatedDate desc])
if((cHistory.newValue == null && cHistory.oldValue == null)
|| (cHistory.newValue != null && !(string.valueOf(cHistory.newValue).startsWith('005') || string.valueOf(cHistory.newValue).startsWith('00G')))
|| (cHistory.oldValue != null && !(string.valueOf(cHistory.oldValue).startsWith('005') || string.valueOf(cHistory.oldValue).startsWith('00G'))))
cHistories tempHistory = new cHistories();
// Set the Date and who performed the action
if(String.valueOf(cHistory.CreatedDate) != prevDate)
tempHistory.theDate = String.valueOf(cHistory.CreatedDate);
tempHistory.who = cHistory.CreatedBy.Name;
tempHistory.userId = cHistory.CreatedBy.Id;
tempHistory.theDate = '';
tempHistory.who = '';
tempHistory.userId = cHistory.CreatedBy.Id;
prevDate = String.valueOf(cHistory.CreatedDate);

// Get the field label
String fieldLabel = CaseHistoriesComponentController.returnFieldLabel(String.valueOf(cHistory.Field));

// Set the Action value
if (String.valueOf(cHistory.Field) == 'created') { // on Creation
tempHistory.action = 'Created.';
else if(cHistory.OldValue != null && cHistory.NewValue == null){ // when deleting a value from a field
// Format the Date and if there's an error, catch it and re
try {
tempHistory.action = 'Deleted ' + Date.valueOf(cHistory.OldValue).format() + ' in <b>' + fieldLabel + '</b>.';
} catch (Exception e){
tempHistory.action = 'Deleted ' + String.valueOf(cHistory.OldValue) + ' in <b>' + fieldLabel + '</b>.';
else{ // all other scenarios
String fromText = '';
if (cHistory.OldValue != null) {
try {
fromText = ' from ' + Date.valueOf(cHistory.OldValue).format();
} catch (Exception e) {
fromText = ' from ' + String.valueOf(cHistory.OldValue);

String toText = '';
if (cHistory.OldValue != null) {
try {
toText = Date.valueOf(cHistory.NewValue).format();
} catch (Exception e) {
toText = String.valueOf(cHistory.NewValue);
if(toText != '')
tempHistory.action = 'Changed <b>' + fieldLabel + '</b>' + fromText + ' to <b>' + toText + '</b>.';
tempHistory.action = 'Changed <b>' + fieldLabel;

// Add to the list

return histories;

// Function to return Field Label of a Case field given a Field API name
public Static String returnFieldLabel(String fieldName)
return CaseHistoriesComponentController.CaseFieldmap.get(fieldName).getDescribe().getLabel();
for(Schema.PicklistEntry pickList : fieldPicklistValues)
if(pickList.getValue() == fieldName)
if(pickList.getLabel() != null)
return pickList.getLabel();
return pickList.getValue();
return '';
// Inner Class to store the detail of the case histories
public class cHistories {

public String theDate {get; set;}
public String who {get; set;}
public Id userId {get; set;}
public String action {get; set;}

  Let me know your views on the code or if you have any questions



I am trying to write a query that will pull a few peices of information from several different tables. It basically is a child object, that queries for details on it's parent object, including getting information from another child object that is attached to that parent. So it goes up to the root, and back down another child. I can get it to read from the parent fine, however writting the subquery to the other child is proving problematic. Just for reference, it is orgniazed like this.


Respondent__c ----> Contact <----- Payments__c


                         ----> Campaign


Respondent is linked to Contact via the Respondent__r relational field, and Payments are linked to Contacts via the Contact__r relational field. Also, a respondent record is linked to two seperate campaigns, but that doesn't really matter for what I'm doing.


The error I get when I run my query is 


"INVALID_TYPE: Respondent__c.Respondent__r.Payment__r.Status__c From Respondent__c.Respondent__r.Payment__r) ^ ERROR at Row:6:Column:63 First SObject of a nested query must be a child of its outer query."


this is my Query


(Select Respondent__c.Respondent__r.Payment__r.Status__c From Respondent__c.Respondent__r.Payment__r),
Respondent__c from Respondent__c  
where Child_Campaign__c = '701400000009Uu4'
order by Respondent__r.lastname


Here is a link to the pertinent sections of my WSDL.



Please let me know if you have any ideas. I just need to be able to select the payment information, If I remoev the sub query it works just fine, but I need that payment info. Otherwise I'm going to have to run another query to fetch it, which I really would rather not do. Thanks!