0
votes

SITUATION: Hi I have a query THAT functions well & as per expectations in salesforce vf page only.

PROBLEM It returns the output without its parent object when calling from an iframe.

The code in apex:

public class showServiceHistory {
CKSW_BASE__Service__c services;
String id = ApexPages.currentPage().getParameters().get('id');
String x;
public myValues()
{
    services = [SELECT id, name, (SELECT Name, Previous_Status__c, New_Status__c, Reason_Code__c, comment__c FROM Service_Status_History__r) FROM CKSW_BASE__Service__c WHERE id=:id];           
}
public String getxx()
{
    x=JSON.Serialize(services);
    return x;   
}
}

The Code In VF

< apex:page controller="myValues" >

< apex:pageBlock title="{!xx}" >

< /apex:pageBlock >

< /apex:page >

Output From Salesforce

{"attributes":{"type":"CKSW_BASE__Service__c","url":"/services/data/v38.0/sobjects/CKSW_BASE__Service__c/sss"},"Id":"s","Name":"S","Service_Status_History__r":{"totalSize":6,"done":true,"records":[{"attributes":{"type":"Service_Status_History__c","url":"/services/data/v38.0/sobjects/Service_Status_History__c/ss"},"Service__c":"asss","Id":"uu","Name":"yyy","Previous_Status__c":"xyz","New_Status__c":"y","Reason_Code__c":"xyz","Comment__c":"abc"}]}

And

Output from iframe

{"attributes":{"type":"CKSW_BASE__Service__c","url":"/services/data/v38.0/sobjects/CKSW_BASE__Service__c/444"},"Id":"444","Name":"xyz"}

From the Vf page I get the desired output with full value, but from an iframe in my force.com url the parent object (nested query) is not available.

However, when I call only parent with a simple dedicated query, it returns the value in both(iframe and url) places.

WHY MY NESTED SOQL IS UNABLE TO GET THE PARENT OBJECT. WHAT I AM MISSING HERE??

Thanks in advance. Please help.

Output from Iframe

2

2 Answers

0
votes

Have you checked your FLS?

Build -> Develop -> Sites -> -> Public Access Settings

This is the culprit most of the times on Force.com outcome.

0
votes

Yes I already checked, It granted public access. And even I am able to see them when converting and printing in JSON format. But I can't see them in iframe if printed with parse object form.

Hence it worked for me by sending values in Json string format and by parsing it over there.

In Vf page

<apex:page Controller="showServiceHistory" sidebar="false" showheader="false">
<html>
    <head>
    <!--<meta http-equiv="refresh" content="20" ></meta> -->

</head>
<a id="history_data" style="display:none;">{!history}</a>
<a id="service_data" style="display:none">{!service}</a>
<style>
    table {
        width: 100%;
    }

    table,
    th,
    td {
        border-collapse: collapse;
        color: #3088D0;
    }

    th,
    td {
        padding: 5px;
        text-align: left;
        color: #1F497D;
    }

    tr {
        //color: #337AB7;
    }

    table#t01 tr:nth-child(even) {
        background-color: #DCE6F1;
        //color: #337AB7;
    }

    table#t01 tr:nth-child(odd) {
        background-color: #fff;
    }

    table#t01 th {
        background-color: #B8CCE4;
        //color: #000015;
    }

    a:link {
        color: #62B3E2;
    }

    a:visited {
        color: #62B3E2;
    }
</style>


<table id="t01">
    <thead>
        <tr>
            <th>
                Name
            </th>

            <th>
                Previous Status
            </th>
            <th>
                New Status
            </th>
            <th>
                Comment
            </th>
        </tr>
    </thead>
    <tbody id="show_values">
    </tbody>

</table>
<script>
    function x()
    {
    var history={}; var service={};
    history=JSON.parse(document.getElementById("history_data").innerHTML); 
    service=JSON.parse(document.getElementById("service_data").innerHTML); 
    var show='';
        for(var i=0;i<history.length;i++)
        {
           show=show+'<tr><td>'+history[i].Name+'</td><td>'+history[i].Previous_Status__c+'</td><td>'+history[i].New_Status__c+'</td><td>'+history[i].Comment__c+'</td><td>'+service.CKSW_BASE__Location__c+'</td></tr>';
        }
            document.getElementById("show_values").innerHTML=document.getElementById("show_values").innerHTML+show;
    }
    x();
</script>
</html>

In apex code page

public class showServiceHistory {
List<Service_Status_History__c> histories;
String x;
CKSW_BASE__Service__c services;
String id = ApexPages.currentPage().getParameters().get('id');
 public showServiceHistory()
{
    services = [SELECT CKSW_BASE__Resource__c, CKSW_BASE__Location__c, (SELECT Name, Previous_Status__c, New_Status__c, comment__c FROM Service_Status_History__r) FROM CKSW_BASE__Service__c WHERE id=:id];         
    histories = services.Service_Status_History__r;
}
public String getService()
{
    return JSON.Serialize(services);   
}
public String getHistory()
{
    return JSON.Serialize(histories);
}

}