I have an SObject say Account which has some not null fields. I want to select all the accounts matching those values. Is there a way I can create a dynamic SOQL query for this.
Suppose the Account object is like this:
Account anAccount = new Account();
anAccount.Name = "sample"
anAccount.CustomName__c = "custom sample"
//Match all account matching above criteria
List<Account> matchingAccounts = [SELECT id from Account where Name=:'sample' AND CustomName__c=:'custom sample'];
I want to make above query dynamically using anAccount instance.