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
RajaMohanRajaMohan 

Help needed for VF Snippet

Hi Folks,

 

I have changed the Account as Companies now. I just want the list of companies as a picklist value in another object called Company Schemes. I just tried of using the VF snippet and added the same into the page layout. But It did not populate the values. Please help me by giving the relavent idea on this. Some codes will be much helpful.

 

Thanks

Raj

MiddhaMiddha

Make sure that Accounts are not set as private in  OWD, if yes use "wihtout sharing" keyword in your VF controller. Also if you can share your code, we could help you faster.

RajaMohanRajaMohan

Hi,

 

Thanks for your reply. Here is my code.

 

Controller:

 

public with sharing class XCD_HRMS_VF_Snippet_CBS {
	
   public List<Account> companyPenScheme=new List<Account>();
   public Employee_Detail__c empDetail;
   public String selectCPS{get;set;}
   public Account account;
   List<SelectOption> selectItem=new List<SelectOption>();
 
   public XCD_HRMS_VF_Snippet_CBS(ApexPages.StandardController stdController){
   	this.account=(Account)stdController.getRecord();
   	this.empDetail=[select id,name,Employee_Name__r.Account.Id from Employee_Detail__c where id=:'a06D000000OJxeL'];//ApexPages.currentPage().getParameters().get('empId')];
   	this.companyPenScheme=[select name,id from Account where Company_Name__c=:empDetail.Employee_Name__r.Account.Id];
   	
   	
   	selectItem.add(new selectOption('--Select--','--Select--'));
   	 for(Account cps:this.companyPenScheme){
   		selectItem.add(new selectOption(cps.name,cps.name));
   	 }
   
   }
   
   public List<SelectOption> getCompanyPensionScheme(){
   	
   	return this.selectItem;
   }
 
}

 

VF Page :

 

<apex:page standardController="Account" extensions="XCD_HRMS_VF_Snippet_CBS" showHeader="false" Label="Company Pension Scheme" name="Company Pension Scheme" tabstyle="Account">
  
  <apex:form >
    
               <apex:outputText value="Company Pension Scheme"/>
                <apex:selectList value="{!selectCPS}" 
                size="1" required="true">
                <apex:selectOptions value="{!CompanyPensionScheme}" />

                </apex:selectList>
   
  </apex:form>

</apex:page>

 

 

Thanks

Raj

 

MiddhaMiddha

1. try to make it without sharing: public WITHOUT sharing class XCD_HRMS_VF_Snippet_CBS {

 

2. Place a system.debug after both the queries and check if you are getting desried results in queries and if not , which query is failing

 

3. Try to access the record "a06D000000OJxeL" from salesforce UI to validate if this is a valid Id and record exists.

 

RajaMohanRajaMohan

Hi,

 

I had done the necessary chages but it does not populate the values. Please help me out.

 

Thanks

Raj

bob_buzzardbob_buzzard

This line looks a little confused to me:

 

 

public XCD_HRMS_VF_Snippet_CBS(ApexPages.StandardController stdController){
   	this.account=(Account)stdController.getRecord();
   	this.empDetail=[select id,name,Employee_Name__r.Account.Id from Employee_Detail__c where id=:'a06D000000OJxeL'];

 specifically the piece highlighted in red.

 

 

The ':' character is used to bind an apex variable into your query, but you have then specified a string literal. 

 

Try changing to:

 

 

public XCD_HRMS_VF_Snippet_CBS(ApexPages.StandardController stdController){
   	this.account=(Account)stdController.getRecord();
   	this.empDetail=[select id,name,Employee_Name__r.Account.Id from Employee_Detail__c where id='a06D000000OJxeL'];