+ Start a Discussion
Sarvesh PrajapatiSarvesh Prajapati 

Visual force query

Hi

I have created 2 objects as Job Application and Candidate, and defined a field candidate on Job Application as relationship. Now I want to display the data from both job application and candidate. Please tell me how I can achieve this. I have written below code, but its not working.

VF Page
<apex:page standardController="Job_Application__c" extensions="extension1">
{!AppCandDet}
</apex:page>

Extension

public class extension1 {
    Candidate__c cand = new Candidate__c();
    Job_Application__c jbap;
    public extension1(ApexPages.StandardController controller)
    {
     jbap=(Job_Application__c)controller.getRecord();
    }

    public string getAppCandDet()
    {  
        cand=[select First_Name__c, Last_Name__c from Candidate__c where Id =:jbap.id];
        return 'Job Application:'+'   Candidate - First Name'+cand.First_Name__c+'  '+cand.Last_Name__c;
    }
}
Best Answer chosen by Sarvesh Prajapati
Mahesh DMahesh D
public class extension1 {
    
    public Job_Application__c jbap {get; set;}
    public extension1(ApexPages.StandardController controller) {
		jbap = (Job_Application__c)controller.getRecord();
		if(jbap != null && jbap.Id != null)
			jbap = [Select Id, Name, Candidate__c, Candidate__r.First_Name__c, Candidate__r.Last_Name__c from Job_Application__c where Id = jbap.Id];
		else
			jbap = new Job_Application__c();
    }
}

You can try this.

Regards,
Mahesh

All Answers

Mahesh DMahesh D
Hi Sarvesh,

Please find the below VF Page:
 
<apex:page standardController="Job_Application__c" extensions="extension1">
	<apex:form>
		<apex:pageBlock>
			<apex:pageBlockSection>
				<apex:outputLabel value="Job App Name"/>
				<apex:outputField value="{!jbap.Name}" />
				<apex:outputLabel value="Candidate First Name"/>
				<apex:outputField value="{!jbap.Candidate__r.First_Name__c}" />
				<apex:outputLabel value="Candidate Last Name"/>
				<apex:outputField value="{!jbap.Candidate__r.Last_Name__c}" />
			</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
</apex:page>

Controller:
 
public class extension1 {
    
    Job_Application__c jbap {get; set;}
    public extension1(ApexPages.StandardController controller) {
		jbap = (Job_Application__c)controller.getRecord();
		if(jbap != null && jbap.Id != null)
			jbap = [Select Id, Name, Candidate__c, Candidate__r.First_Name__c, Candidate__r.Last_Name__c from Job_Application__c where Id = jbap.Id];
		else
			jbap = new Job_Application__c();
    }
}

I couldnt execute it my system, please verify and let me know if any issues.

Regards,
Mahesh
Sarvesh PrajapatiSarvesh Prajapati
Hi Mahesh

I'm getting below error.

Error: Unknown property 'Job_Application__cStandardController.jbap

Sarvesh
Mahesh DMahesh D
public class extension1 {
    
    public Job_Application__c jbap {get; set;}
    public extension1(ApexPages.StandardController controller) {
		jbap = (Job_Application__c)controller.getRecord();
		if(jbap != null && jbap.Id != null)
			jbap = [Select Id, Name, Candidate__c, Candidate__r.First_Name__c, Candidate__r.Last_Name__c from Job_Application__c where Id = jbap.Id];
		else
			jbap = new Job_Application__c();
    }
}

You can try this.

Regards,
Mahesh
This was selected as the best answer
Sarvesh PrajapatiSarvesh Prajapati
Hi Mahesh,

Its working.

Thanks.