You need to sign in to do that
Don't have an account?
Himanshu Ghate
I am getting problem form this code? Can some please help me.
String accountdata='Hello';
String dyncquery='Select id, Name, Industry , Type From Account';
if(accountdata=='Hello')
{
dyncquery +='WHERE Industry=\'Agriculture\' AND Type=\'Prospect\'';
}else if(accountdata=='Helloworld')
{
dyncquery +='WHERE Industry=\'Banking\' AND Type=\'Customer - Direct\' ';
}
else{
dyncquery +='WHERE Industry=\'Construction\' ';
}
List<Account> accounts=Database.query(dyncquery);
System.debug('Account Record:'+accounts);
System.debug('Account Size:'+accounts.size());When I remove the Industry ,Then it show on Type that
Line: 13, Column: 1
System.QueryException: unexpected token: Type
Line: 13, Column: 1
System.QueryException: unexpected token: Industry
String dyncquery='Select id, Name, Industry , Type From Account';
if(accountdata=='Hello')
{
dyncquery +='WHERE Industry=\'Agriculture\' AND Type=\'Prospect\'';
}else if(accountdata=='Helloworld')
{
dyncquery +='WHERE Industry=\'Banking\' AND Type=\'Customer - Direct\' ';
}
else{
dyncquery +='WHERE Industry=\'Construction\' ';
}
List<Account> accounts=Database.query(dyncquery);
System.debug('Account Record:'+accounts);
System.debug('Account Size:'+accounts.size());When I remove the Industry ,Then it show on Type that
Line: 13, Column: 1
System.QueryException: unexpected token: Type
Line: 13, Column: 1
System.QueryException: unexpected token: Industry
Try below updated code
Basically, you need to give space before WHERE condition in your dynamic query
If this information helps, please mark the answer as best. Thank you
All Answers
Try below updated code
Basically, you need to give space before WHERE condition in your dynamic query
If this information helps, please mark the answer as best. Thank you