You need to sign in to do that
Don't have an account?
Bridgetree
looup field in where cluase.
HI allll...
I am trying to write a query in which for the where cluase i would like to check with a lookup field.
How this can be done. Please suggest.
ex: Select Product_name__c from Franchisee__c where Franchisee_name__c=
Here Franchisee_name__c is a lookup field refering to accounts.
Please suggest I am New to this Envi
Thanks in advance
Lookup fields, under the hood, store Salesforce Ids.
So you would need to match on the Account Id
Say you had a variable Account
Account acc = .....
Then
Select Product_name__c from Franchisee__c where Franchisee_name__c = :acc.Id;
Or if you had a list of Account Ids
List<Id> accIds = ....
Select Product_name__c from Franchisee__c where Franchisee_name__c IN :accIds
This works but the requirement is like this.
I enter the account name in a text box. So in the solution given, you can never tell which account is been refered too.
So the account selection must be done based on the text entered.
Help.
Thanks in advance
Not sure, but seems like you're using a VF page and this executes in your controller ?
Reckon you need to search for the Account based on the text you entered
Account acc = [Select Id, Name from Account where Name = :textBoxFieldValue];
Select Product_name__c from Franchisee__c where Franchisee_name__c = :acc.Id;
This would work only when you ensure the account names are unique. When you have 2 accounts created with the same name, which is possible by default your code would break.
In these use cases always use lookup fields or you would run into issues one day or the other.