function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hemant ranahemant rana 

I have created a dynamic soql in controller but while using it with IN operator its not showing the query properly

I have created a dynamic soql in controller but while using it with IN operator its not showing the query properly....
<apex:page controller="dynamicsoql">
    <apex:form>
        <apex:pageBlock >
            <apex:pageBlockSection id="pbs">
                <apex:outputText>{!idinlist}</apex:outputText>
                <apex:inputTextarea value="{!query}" />
            </apex:pageBlockSection>
            <apex:commandButton action="{!showid}" value="showid" reRender="pbs"/>
            <apex:commandButton action="{!showquery}" value="showquery" reRender="pbs"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>
.........................................................................
public class dynamicsoql {
    public list<j__c> recordid { get; set; }
    public string singleid{get;set;}
    public list<string> idinlist{get;set;}
    public string query {get;set;}
    public dynamicsoql()
    {
     recordid=[select id from j__c];
     idinlist=new list<string>();
    }
    public void showid()
    {
        for(j__c j: recordid)
        {
            singleid='\''+string.valueOf(j.id)+'\'';
            idinlist.add(singleid);
        }
    }
    public void showquery()
    {
        query ='select name from j__c where id in '+  idinlist ;
    }
}

In my controller their is a dynamic soql query----

(((((((((((query ='select name from j__c where id in '+  idinlist ;))))))))))))))))

in this query ""idinlist"" is a list of id's. If in the list their are only 10 id then its fine and the query is printed in the vf page in this form
select name from j__c where id in ('a019000000FRJDkAAP', 'a019000000FRJDzAAP', 'a019000000FRJEdAAP', 'a019000000FRJEeAAP', 'a019000000FRJFCAA5', 'a019000000FRJFDAA5', 'a019000000FRJFEAA5', 'a019000000FRJFFAA5', 'a019000000FRJFlAAP', 'a019000000FRJGSAA5')

but if  ""idinlist"" has more then 10 id's then its query is printed in this form

select name from j__c where id in ('a019000000FRJDkAAP', 'a019000000FRJDzAAP', 'a019000000FRJEdAAP', 'a019000000FRJEeAAP', 'a019000000FRJFCAA5', 'a019000000FRJFDAA5', 'a019000000FRJFEAA5', 'a019000000FRJFFAA5', 'a019000000FRJFlAAP', 'a019000000FRJGSAA5',...)

means after 10th id it's just showing '''...''' and no id. i had printed the query in vf page system debug every where it's the same.
and because of that my query is not working. Please help.


Vamsi KrishnaVamsi Krishna
Hemant,
my understanding is that the "..." shows up only in the UI..
thats how salesforce renders long text fields.. in debug logs or in VF pages.. but internally the strings should be stored with complete values..

did you actually run the query and got any errors ?
hemant ranahemant rana
Yes while running the query its giving this error....
System.QueryException: expecting a colon, found '.'
Error is in expression '{!showquery}' in component <apex:commandButton> in page dynamicsoql
sunny522sunny522
Hi Hemanth,

             Its default salesforce behaviour.It doesnot mean your functionality is wrong.For example if you query for 1000 records it takes so much space to specify.so in general it displays some and then it says so on.....

if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Amritesh SahuAmritesh Sahu
Hi Hemant,

Use this
public void showquery()
    {
       List<j__c> j_list= [select id,name from j__c where id in :idinlist];
    }

Hope this helps
Regards.
Qui TranQui Tran

Hi Hemant, 

I met similar issue as yours and have work-around, I think the problem is on "where id in :idinlist".  It will limit your string with ... at the end if the list has more than 10 records.

The work-around as code below:

Instead of use "where id in :idinlist", 

You could use (tested okay in my app)

String queryString = 'select id,name from j__c where ';
String tmp1 = ' Id IN (';
for (integer i = 0; i< idinlist.size(); i++){
                if (i == 0){
                    tmp1 += idinlist[i];
                } else {
                    tmp1 += ',' + idinlist[i];
                }
 }
 tmp1 += ' )';
 queryString += tmp1;


BR