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
Aidan KeenanAidan Keenan 

How to relate a standardcontroller to a custom object

How do I relate a standardcontroller to a custom object on a visual force page 
<apex:page standardController="ts2__Placement__c"  showHeader="false" sidebar="false">
  <p>You are viewing the {!ts2__Placement__c.name} record .</p>
Sample Encrypted Bank Account:  <apex:outputField value="{!ts2__Placement__c.Sample_Bank_Acc__c}" /><br />
</apex:page>

I am getting a error saying I cannot use the custom object on the visualforce page when I try to do this.
Sonam_SFDCSonam_SFDC
hey Shane,

This is actually the correct way to call a standard controller of a custom object - I've tried the same code on my test ORG and it works - where are you using this visualforce page? Did you try passing the ID of the ts2__Placement__c record in the url? A screen shot of the error message would help here.
Aidan KeenanAidan Keenan
Hi

Thanks for the reply. What I am trying to do is send an encrypted custom field in a visualforce e mail template to payroll when a new placement is made. Because encrypted custom field are masked in an e mail template. I am trying the workaround where I create a visualforce page which does decrypt the custom field.Then using an iframe to insert this into the e mail template. My problem is on the e mail template I am using 

Encrypted Account Number: <apex:outputText value="{!relatedTo.ts2__Employee__r.Sample_Bank_Acc__c}"/>

This brings me back the bank account number encrypted. I want to use pull this value ont a visualforce page but can not use the relatedTo attribute as it is only for e mail templates?  

So my page is now working 

<apex:page standardController="ts2__Placement__c"  showHeader="false" sidebar="false">
  <p>You are viewing the {!ts2__Placement__c.name} record .</p>
Sample Encrypted Bank Account:  <apex:outputField value="{!ts2__Placement__c.ts2__Employee__r.Sample_Bank_Acc__c}" /><br />
</apex:page>

This is calling the encrypted field  from the placement relating it to the Contact object where the encrypted field is located.
However when I call the iframe on the e mail template I do not know how to relate it the record.

 <apex:iframe src="/apex/testEncrypted2?id=a0zZ0000001SGeM" scrolling="true" id="theIframe"/>

I have hard coded the a0zZ0000001SGeM  for testing. This is showing the bank accuount decrypted but obviously I can not hard code this so I need to know how to relate the visualforce page to the particular placement ID.  I have tried 

<apex:iframe src="/apex/testEncrypted2?id={!ts2__Placement__c.Id}" scrolling="true" id="theIframe"/>

But this is giving me a error message saying that this is an invalid ID. Is there a way similar to relatedTo that I am using in the e mail template that I can place where id=  in the iframe that will get the right record for me.

Lori BuchowiczLori Buchowicz
Were you able to easily create an Apex Test for this?  I am struggling as my apex class and VFP in Sandbox working well but I cannot get my lookup objects in the test case without a multitude of errors.