You need to sign in to do that
Don't have an account?
Mike Parks 5
Compile Error: Illegal assignment from List
I keep getting this error when I try to save the following code...any idea what I've got wrong?
Error: Compile Error: Illegal assignment from List<Proposal__c> to Id at line 13 column 3
public with sharing class AnotherController
{
private ApexPages.StandardController stdCtrl;
public AnotherController(ApexPages.StandardController std)
{
stdCtrl=std;
}
public void PopulateProject()
{
Project__c proj=(Project__c) stdCtrl.getRecord();
proj.Proposal__c=[select Scope_of_Work__c from Proposal__c where Id=:proj.Proposal__c];
proj.Scope_of_Work__c=proj.Proposal__c.Scope_of_Work__c;
}
}
Error: Compile Error: Illegal assignment from List<Proposal__c> to Id at line 13 column 3
public with sharing class AnotherController
{
private ApexPages.StandardController stdCtrl;
public AnotherController(ApexPages.StandardController std)
{
stdCtrl=std;
}
public void PopulateProject()
{
Project__c proj=(Project__c) stdCtrl.getRecord();
proj.Proposal__c=[select Scope_of_Work__c from Proposal__c where Id=:proj.Proposal__c];
proj.Scope_of_Work__c=proj.Proposal__c.Scope_of_Work__c;
}
}
you are trying to assign list of Proj.Proposal__c to id. try some other Operator "IN" insted of " =: "
Hope it will help you.
Thanks
Karthik
This line contains error
proj.Proposal__c=[select Scope_of_Work__c from Proposal__c where Id=:proj.Proposal__c];
Above query returns list and Proj.Proposal__C is of id type
So try something like this If it helps make it as best answer.
Thanks.
SOQL statement, returns list of records.So, you need a list of datatype Proposal__c to store the list of records returned by the SOQL statement.
Eg: List<Proposal__c> prop = new List<Proposal__c> ();
prop=[select Scope_of_Work__c from Proposal__c where Id=:proj.Proposal__c];
By the way, what's your requirement?What's the relation between Project__c and Proposal__c ?
When I'm entering a new Project__c, and select the related Proposal__c, I'm trying to auto complete several fields on the new Project__c screen before Saving. And I need the auto completed fields to be editable as well.
I found an example in this forum for Contacts and Accounts that works exactly like I need. Here's the code for the example that is working:
public with sharing class RelatedController
{
private ApexPages.StandardController stdCtrl;
public RelatedController(ApexPages.StandardController std)
{
stdCtrl=std;
}
public void AccountPopulated()
{
Contact cont=(Contact) stdCtrl.getRecord();
cont.Account=[select NAICS__c, DUNS_Number__c from Account where id=:cont.AccountId];
cont.NAICS__c=cont.Account.NAICS__c;
}
}
juat look at the where condition they check with id=:cont.accountid.
But in your case you are check id with entire object insted if this kinldy check like below
id=:proj.Proposal__c.id
hope it will work for you
makr best ans if it's work.
Thanks
karthik
Error: Compile Error: Invalid foreign key relationship: Project__c.Proposal__c at line 13 column 72
I guess I don't understand why this same line from the working example:
cont.Account=[select NAICS__c, DUNS_Number__c from Account where id=:cont.AccountId];
is working without problem.
One thing I see is cont.Account is named differently from cont.AccountId whereas in my code
proj.Proposal__c=[select Scope_of_Work__c from Proposal__c where Id=:proj.Proposal__c];
proj.Proposal__c is named exactly the same as proj.Proposal__c
So it's like for the std object something is different from my custom object.
Hello mike
account is the standard object.your trying to use custom object so you have to use like below
id=:proj.Proposal__r.id
Note: also make sure the right relationship with those 2 objects.
Coz Account and Contact Document wise lookup relationship. but while working with this object like is there is any account is assiciated with contact it would act as master details relationship like delete account will associated contact also delete.
thanks
karthik
public with sharing class RelatedController1
{
public Proposal__c prop {get;set;}
private ApexPages.StandardController stdCtrl;
public RelatedController1(ApexPages.StandardController std)
{
stdCtrl=std;
}
public void PopulateProject()
{
Project__c proj=(Project__c) stdCtrl.getRecord();
prop=[select Name, SOW__c, Scope_of_Work__c, Contact__c from Proposal__c where Id=:proj.Proposal__c];
proj.SOW__c=prop.SOW__c;
proj.Name=prop.Name;
proj.Scope_of_Work__c=prop.Scope_of_Work__c;
proj.Project_Contact__c=prop.Contact__c;
}
}
Adding the line: public Proposal__c prop {get;set;}
And then I was able to say....
prop=[select Name, SOW__c, Scope_of_Work__c, Contact__c from Proposal__c where Id=:proj.Proposal__c];
is working perfectly now.
So if you ever need to auto populate editable fields based on selecting a related object lookup value...this is how you do it!