You need to sign in to do that
Don't have an account?

Please help : <apex:inputField> can only be used with SObjects
Hi All,
I am creating a single entry form page of opportunities and cuboid__c. Cuboid__c has a lookup relation to opportunities. I want one page which comprises of fields from both the objects. I have created a visulforce page but I am getting this error.
Error: Could not resolve the entity from <apex:inputField> value binding '{!Opp.Name}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.
<apex:page id="page" Controller="newopportunitycontroller">
<apex:form >
<apex:pageMessages />
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!save}" value="save"/>
<apex:commandButton action="{!cancel}" value="cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Opportunity Information" collapsible="true" columns="1" >
<apex:pageBlockSectionItem id="accountSectionItem">
<apex:outputLabel id="OpportunityNameLabel" for="opportunityName" value="Opportunity Name" />
<apex:inputField id="OpportunityName" value="{!Opp.Name}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="schedules and actuals" collapsible="true">
<apex:pageBlockSectionItem id="contactFirstNameSectionItem">
<apex:outputLabel id="cuboidheight" for="cuboiddheight" value="Height" />
<apex:inputField id="cuboidddheight" value="{!cub.height__c}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Below is the apex class which is also giving this error:
Didn't understand relationship 'Opportunity__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 17 column 15
Hi,
First solve below error.
cub = [select id, height__c from cuboid__c where Opportunity__r.Id = :opp.Id];
Here you have used wrong query.
Custom object cuboid__c having lookup field related to Opportunity?
What is the name of lookup field in cuboid__c object?
Suppose its a Opportunity__c then simply use same name.
i.e.
cub = [select id, height__c from cuboid__c where Opportunity__c = :opp.Id];
Hi,
I made the changes. Lookup field is trial_Field__c. But I still getting the error.
Error: Compile Error: Illegal assignment from SOBJECT:Opportunity to opportunity at line 16 column 9
public class newopportunitycontroller
{
public PageReference cancel() {
return null;
}
public Opportunity opp {get; set;}
public List<Cuboid__c> cub {get; set;}
public newopportunitycontroller() {
String id = ApexPages.currentPage().getParameters().get('id');
opp = [select id, Name from Opportunity where Id = :id][0];
cub = [select id, height__c,trial_field__c from cuboid__c where trial_Field__c = :opp.Id];
}
public PageReference save() {
insert opp;
insert cub;
return null;
}
}
Thanks for your help
yes
Give object name and all other information about this field.
Otherwise your code has no error.
Hi,
I understood what you are trying to say. it's my fault that I could not present the problem in an effiecient manner. So basically cuboid__c and opportunity are unrelated objects. I just want to create single entry form page for business users to enter opportunity information and in the related lists section they can also enter cuboid__c information
Trial_field__c is a lookup field created on custom object called cuboid__c and its look up to some other object called xyz__c. Can you fix the code now or provide me any suggestion ?
So you cannot write below query.
cub = [select id, height__c,trial_field__c from cuboid__c where trial_Field__c = :opp.Id];
as trial_Field__c is not related to Opportunity and you are trying to compare it with opp.Id which cause problem.
But you want to retrieve some cuboid records based on some opportunity fields right?
So can you please give some detail, which fields you want to compare with opportunity?
I dont want to retrieve any records from cuboid__c. I just want a visualforce form page. Where users can just enter the opportunity fields information and also the cuboid__ c field information. when they fill the form they will click the save button and record will be saved to their respective objects (cuboid__c & opportunity)
means, instead of below query
cub = [select id, height__c,trial_field__c from cuboid__c where trial_Field__c = :opp.Id];
use below query
cub = [select id, height__c,trial_field__c from cuboid__c Limit 500];