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
VSK98VSK98 

Dynamic Apex

Hi,

i have one SOQL query like 
SELECT id FROM businesshours WHERE Name = 'UK'
Is it possible to get using dynamic apex...........................

Adv Thnx
VSK
Jagadeesh111Jagadeesh111

Hi VSK,

It is possible, Please post your clear scenario here.

In SOQL query through bind variable we can pass dynamic values for query.

Below is one way..

String strName = 'yourName';

List<Businesshours__c> lstBusinesshours = [SELECT Id, Name FROM Businesshours__c Where Name =: yourName];

Thanks,

Jagadeesh.

VSK98VSK98
Hi Jagadessh,

I dont wanna use SOQL Query here...............want to do with dynamic Apex
InfuInfu
Hi VSK,

Try this one,
 
String yourName; 
List<Account> listAcct = Database.query('SELECT Id, Name FROM Businesshours__c Where Name =: yourName');

Thanks,
Infu.
Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hope that will help you
1) http://amitsalesforce.blogspot.in/search/label/Apex%20Describe
public Void GetAllField()
{
 String query ='';
 String SobjectApiName = 'Account';
 Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
 Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();

 String strFields = '';
 
 for(String fieldName : fieldMap.keyset() )
 {
  if(strFields == null || strFields == '')
  {
   strFields = fieldName;
  }else{
   strFields = strFields + ' , ' + fieldName;
  }
 }

 query = 'select ' + strFields + ' from ' + SobjectApiName + ' Limit 10 ';

 List <Account> accList = Database.query(query);
 
}
Let us know if this will help you

Thanks
Amit Chaudhary

 
sandeep reddy 37sandeep reddy 37
we will write no of type dynamic soql like using database.query();
and first you need to decleare one variable what you want pass
public class dynamic {
public string name{set;get;}
(or)
public date birthday{set;get;}
public list<account> acc{set;get;}
public void dynamic(){
acc=[select industry,phone from account where name=:sham ];
}
}
<apex:page controller ="dynamic">
<apex:form>
<apex:inputtext value="{!name}"/>
<apex:commandbutton value="view" action={!dynamic}>
<apex:pageblock title ="display details">
<apex:pageblocktable valuu="{!accx}" var="a">
<apex:colunm value="{!a.industry}"/>
<apex:colunm value="{!a.phone}"/>
</apex:pageblocktabel>
</apex:pageblock>
</apex:form>
</apex:page>

just try this man and tell me i hope this is help ful for u
 
Srinivas SSrinivas S
Database.query('SELECT id FROM businesshours WHERE Name = /'UK/'');
------------------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.