You need to sign in to do that
Don't have an account?
Satya413
Get Record ID from selected value in Lookup
Hi,
I am trying to display the account record details as well as the related contacts and opportunities for a selected account record through lookup.
I am stuck at the point where I am unable to obtain the record id for the selected account record.
Below is my code. Any help is appreciated.
VF Page:
<apex:page controller="accountdisplay">
<apex:form>
<apex:pageBlock title="Display Account Details">
<apex:outputText value="Select Account: " />
<apex:inputField value="{!con.accountid}"/>
<apex:commandButton action = "{!getdetails}" value='Submit' />
<apex:pageBlockSection title="Account Details">
<apex:outputtext value="{!acc.name}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class AccountDisplay {
public account acc {get; set;}
public contact con {get; set;}
public pagereference getdetails(){
acc = [select id, name from account where id = :con.AccountId];
return null;
}
}
Thank You,
Satya
I am trying to display the account record details as well as the related contacts and opportunities for a selected account record through lookup.
I am stuck at the point where I am unable to obtain the record id for the selected account record.
Below is my code. Any help is appreciated.
VF Page:
<apex:page controller="accountdisplay">
<apex:form>
<apex:pageBlock title="Display Account Details">
<apex:outputText value="Select Account: " />
<apex:inputField value="{!con.accountid}"/>
<apex:commandButton action = "{!getdetails}" value='Submit' />
<apex:pageBlockSection title="Account Details">
<apex:outputtext value="{!acc.name}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class AccountDisplay {
public account acc {get; set;}
public contact con {get; set;}
public pagereference getdetails(){
acc = [select id, name from account where id = :con.AccountId];
return null;
}
}
Thank You,
Satya
Please do the changes in your class as mention below
Thanks,
Keyur Modi
All Answers
Please do the changes in your class as mention below
Thanks,
Keyur Modi
Thanks for your reply. It worked. However, can you please explain your code especially the system.debug part.
Thank you,
Satya
Only one diffrance between my code and your code is you had not created the instance of the two object contact and account ... and so i create the instace of both oject in constructor so whenever your page load it will create instace for both object. so it will not give the error which you faced before.
i hope this clarification will make your doubt clear .. if still you have any confusion feel free to ask,
Thanks,
Keyur Modi
Satya