You need to sign in to do that
Don't have an account?
Sub Query Problem
Hai,
I have problem with SubQuery,which is Marked Below.
Here I want to Query According to Owner,Which is User Accountid.
I am getting Error.
Can you please help me how to write that Query.
user use=[select id,accountid from user where id=:userinfo.getuserid()];
string UserAccount=use.accountid;
public ApexPages.StandardSetController con {
get{
if(con == null) {
con = new ApexPages.StandardSetController(Database.getQueryLocator([select id,o2bc__Sell_Price__c,o2bc__Item_Code__c,name,Qty__c,(SELECT ContentType,attachment.id FROM o2bc__Item__c.attachments WHERE ContentType LIKE '%image%'),(select o2bc__item_serial__c.id,name,owner__c from o2bc__item_serials__r where o2bc__status__c='new'and Owner__c=\'+UserAccount+\') from o2bc__Item__c where o2bc__Type__c IN ('UpgradedPhones') and o2bc__Sell_Price__c!=0 order by o2bc__Sell_Price__c ]));
con.setPageSize(18);
}
return con;
}
set;
}
Please help me how to Query that value.
What is the error you're getting?
What error you are getting?
Also, you should use : to use variable in SOQL queries. like
Owner__c= :UserAccount
Let me know if it helps.
Regards,
-P
Thanks for you reply,
I implemented like this also as you said ,Its showing error as:
MALFORMED_QUERY: (o2bc__status__c = 'new' and Owner__c = :tmpVar1)) from o2bc__Item__c ^ ERROR at Row:1:Column:256 unexpected token: ':'
Hai Vishal Thanks for your reply
I used Query like below and getting error as
MALFORMED_QUERY: (o2bc__status__c = 'new' and Owner__c = :tmpVar1)) from o2bc__Item__c ^ ERROR at Row:1:Column:256 unexpected token: ':'
(select o2bc__item_serial__c.id,name,owner__c from o2bc__item_serials__r where o2bc__status__c='new'and Owner__c=:UserAccount)
Can you share your query after modification?
Vishal,This is the Query I am getting error :
MALFORMED_QUERY: (o2bc__status__c = 'new' and Owner__c = :tmpVar1)) from o2bc__Item__c ^ ERROR at Row:1:Column:256 unexpected token: ':'
user use=[select id,accountid from user where id=:userinfo.getuserid()];
string UserAccount=use.accountid;
public ApexPages.StandardSetController con {
get{
if(con == null) {
con = new ApexPages.StandardSetController(Database.getQueryLocator([select id,o2bc__Sell_Price__c,o2bc__Item_Code__c,name,Qty__c,(SELECT ContentType,attachment.id FROM o2bc__Item__c.attachments WHERE ContentType LIKE '%image%'),(select o2bc__item_serial__c.id,name,owner__c from o2bc__item_serials__r where o2bc__status__c='new'and Owner__c=:UserAccount from o2bc__Item__c where o2bc__Type__c IN ('UpgradedPhones') and o2bc__Sell_Price__c!=0 order by o2bc__Sell_Price__c ]));
con.setPageSize(18);
}
return con;
}
set;
}
Youhave used 2 froms in your query, so you have not closed your sub query properly.
select o2bc__item_serial__c.id,name,owner__c from o2bc__item_serials__r where o2bc__status__c='new'and Owner__c=:UserAccount from o2bc__Item__c
Thanks for your reply prakash.
After UserAccount there is cclose bracket.I forgot to kept that one here. That is not the problem.Here I am unable to use Outside variable in inner query.
Can you Explain me if you know.
select o2bc__item_serial__c.id,name,owner__c from o2bc__item_serials__r where o2bc__status__c='new'and Owner__c=:UserAccount)