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

Convert Sobject query to string values



I am currently working on a visualforce page that is going to be used in a sites email campaign. Turns out Opportunity does not work well with sites so I need some help taking my query of Opportunity and placing values into string fields (or list, whichever works).


Opportunity record ID is passed through the email so that is used in the query, also keeps it limited to 1 per page so that should make it easier to deal with.


Here is a shot of how I am querying:


public with sharing class rrdipus {

//Collect Opportunity ID to use in query
public string uniqueID = System.currentPagereference().getParameters().get('q'); 
public string getUniqueID() { return uniqueID; }

public list<Opportunity> getDetails() 
		return [SELECT Project_Street__c, Project_City__c, Project_State__c, Project_Zip__c, Proj_Country__c, Proj_Expiration__c, Proj_RSF__c
                FROM Opportunity
                WHERE Id = :uniqueID ];



As for the VF apge, I know how to display everything needed - just confused how to get those values returned in the query to a string field.


Example: I would like to take Project_Street__c and place it into a string field called thestreet or something like that.


Thanks in advance,

Best Answer chosen by Admin (Salesforce Developers) 

Ahhh yes.  Certain standard objects are restricted.  Try putting the Opportunity in a Wrapper class that has the 'without sharing' on it.  That way the page will keep its security except where opportunities are concerned.

All Answers


I actually just tried this:


public String siteStreet
        get {return [SELECT _Project_Street__c FROM Opportunity WHERE Id = :uniqueID].Project_Street__c; }

 Then to display it on the VF page:


<apex:outputText value="{!siteStreet}" / >


This shows the proper output on my editor, but results in the "Authorization Required" page from sites.


Went through and checked that all the fields on Opportunity are viewable to the sites profile so that is confirmed.


Not sure what the issue is.



i could not understand your requirement well,Do you want to assign the fields which coming from query to a string value?



I am looking for a way to display the opportunity fields on my sites page. Just as output, they will be inputting to a different custom object so that part is ok.


I figured if I could not get the values to display as opportunity output fields, then converting them to a string value and displaying would work fine but turns out I am now getting a "Auth Required" page.


Does that make sense?


Gotcha,Use a inline wrapper class then display them as a string like:


public with sharing class OppClass


public OppWrapper OppItem {get;set;}

public OppClass()


OppList=new List<OppWrapper>();

opportunity ExistedOpps=[select Project_Street__c,... from Opportunity where Id:=uniqueId];

                OppItem=new OppWrapper(ExistedOpps);


public class OppWrapper


public Id wrapperID;

public String ProjectStreet;


public OppWrapper(Opportunity oppitem)








I am recieving an error about the OppList=new List<OppWrapper>(); line.



Here is the error:
Save error: Illegal assignment from LIST<rrdipus.OppWrapper> to rrdipus.OppWrapper


I don't believe you require a Wrapper for your requirements:


Use your existing getDetails function.


Use this in your page.

<apex:repeat value="{!details}" var="opp">
	<apex:outputField value="{!details.Name}" />
	<!-- repeat the same for each field you want -->
        <!-- optionally use an <apex:pageBlockTable>





Oops my bad.  I misread requirements... again.  Make your controller an extension

You will have access to all of your fields and can do whatever you would like with them.



Yes, that is what I was trying but it won't show the opportunity values (I have done this with many VF pages using custom objects and never had an issue).


In my editor I see everything show up as it should... Reload the sites page and nothing appears. 


Is it showing nothing when you are viewing it through sites or normal Salesforce?  When you are viewing through Sites, it uses the Sites user permissions.  You must make sure that these are correct for the user.


Try to remove the 'with sharing' to have a look without some of these permissions.


NOTE-This will cause a security issue, so I would only remove it for testing to see if the security you have set up is what causes it.




I just tried removing the 'with sharing' and it worked to display the string.


As for putting 'with sharing' back on, it will not display anything - I have all fields accessible to the sites user through the sites settings. Access to objects, fields, class and page all look good.


The owner's of these projects are higher on the Role Heirarchy than other users in the system, would that cause this to not work?


Try adding the 'View All' property for all of the Sites user settings.


Opportunity does not have a View All property under the site public setting.


Is there another place I should be looking? Like something that controls sites globally?


Ahhh yes.  Certain standard objects are restricted.  Try putting the Opportunity in a Wrapper class that has the 'without sharing' on it.  That way the page will keep its security except where opportunities are concerned.

This was selected as the best answer