You need to sign in to do that
Don't have an account?
MoreThanWYSIWYG
Getting "Initial term of field expression must be a concrete SObject: LIST" on an IF statement
Hi, this is my first coding project with SF. I'm a n00b when it comes to programming in general.
The code below is just running through different areas where a phone number can be stored. On Checking billing__contact__phone__c and Checking Contact Fax, I get the error in the title of this post. The other ifs work fine. I can run the queries against the DB with no problem. What is going on here.
String CID = '(555) 555-5555';
List<Contact> conMobile = [SELECT MobilePhone, Dealer_Portal_Account_Created__c FROM Contact WHERE MobilePhone = :CID limit 1];
//Checking Contact Mobile Phone
if (!conMobile.isEmpty()){
System.debug('Contact Mobile Phone: ' + conMobile);
}
//Checking Contact Phone
else if (conMobile.isEmpty()){
List<Contact> conPhone = [SELECT Phone, Dealer_Portal_Account_Created__c FROM Contact WHERE Phone = :CID limit 1];
System.debug('Contact Phone: ' + conPhone);
//Checking Account Phone
if (conPhone.isEmpty() && conMobile.isEmpty()){
List<Account> accPhone = [SELECT Phone FROM Account WHERE Phone = :CID limit 1];
System.debug('Accout Phone : ' + accPhone);
//Checking Account FAX
if (conPhone.isEmpty() && conMobile.isEmpty() && accPhone.isEmpty()){
List<Account> accFax = [SELECT Fax FROM Account WHERE Fax = :CID limit 1];
System.debug('Accout Fax : ' + accFax);
//Checking billing__contact__phone__c
if (conPhone.isEmpty() && conMobile.isEmpty() && accPhone.isEmpty && accFax.isEmpty()){
List<Account> accBillingPhone = [SELECT Billing_Contact_Phone__c FROM Account WHERE Billing_Contact_Phone__c = :CID limit 1];
System.debug('Account Billing Phone : ' + accBillingPhone);
//Checking Contact Fax
if (conPhone.isEmpty() && conMobile.isEmpty() && accPhone.isEmpty && accFax.isEmpty() && accBillingPhone.isEmpty()){
List<Contact> conFax = [SELECT Fax FROM Contact WHERE Fax = :CID limit 1];
System.debug('Contact Fax : ' + conFax);
}
}
}
}
}
else{
System.debug('Nothing');
}
//account portalLoginCreatedEmailed__c
The code below is just running through different areas where a phone number can be stored. On Checking billing__contact__phone__c and Checking Contact Fax, I get the error in the title of this post. The other ifs work fine. I can run the queries against the DB with no problem. What is going on here.
String CID = '(555) 555-5555';
List<Contact> conMobile = [SELECT MobilePhone, Dealer_Portal_Account_Created__c FROM Contact WHERE MobilePhone = :CID limit 1];
//Checking Contact Mobile Phone
if (!conMobile.isEmpty()){
System.debug('Contact Mobile Phone: ' + conMobile);
}
//Checking Contact Phone
else if (conMobile.isEmpty()){
List<Contact> conPhone = [SELECT Phone, Dealer_Portal_Account_Created__c FROM Contact WHERE Phone = :CID limit 1];
System.debug('Contact Phone: ' + conPhone);
//Checking Account Phone
if (conPhone.isEmpty() && conMobile.isEmpty()){
List<Account> accPhone = [SELECT Phone FROM Account WHERE Phone = :CID limit 1];
System.debug('Accout Phone : ' + accPhone);
//Checking Account FAX
if (conPhone.isEmpty() && conMobile.isEmpty() && accPhone.isEmpty()){
List<Account> accFax = [SELECT Fax FROM Account WHERE Fax = :CID limit 1];
System.debug('Accout Fax : ' + accFax);
//Checking billing__contact__phone__c
if (conPhone.isEmpty() && conMobile.isEmpty() && accPhone.isEmpty && accFax.isEmpty()){
List<Account> accBillingPhone = [SELECT Billing_Contact_Phone__c FROM Account WHERE Billing_Contact_Phone__c = :CID limit 1];
System.debug('Account Billing Phone : ' + accBillingPhone);
//Checking Contact Fax
if (conPhone.isEmpty() && conMobile.isEmpty() && accPhone.isEmpty && accFax.isEmpty() && accBillingPhone.isEmpty()){
List<Contact> conFax = [SELECT Fax FROM Contact WHERE Fax = :CID limit 1];
System.debug('Contact Fax : ' + conFax);
}
}
}
}
}
else{
System.debug('Nothing');
}
//account portalLoginCreatedEmailed__c
But... there is an easier way to search for a phone number in a multiple objects - use SOSL (http://www.salesforce.com/us/developer/docs/soql_sosl/index_Left.htm#CSHID=sforce_api_calls_sosl.htm|StartTopic=Content%2Fsforce_api_calls_sosl.htm|SkinName=webhelp). For example, this single query will return an Account and two Contacts in a standard Developer Edition org:
FIND {"\(312\) 596\-1000"} IN PHONE FIELDS RETURNING Account, Contact, Lead
I will use the the find method, that is so much better than what I have, way cleaner. Thanks for the point in the right direction.
I re-wrote the code like this:
public class five9Query{
public String getFive9URL()
{
return ApexPages.currentPage().getHeaders().get('referer');
}
public static void runFive9Query()
{
String CID = '(555) 555-5555'; // this is just for testing. will be passed via URL when implimented.
//this needs to become a class that is called by a visual force page. From the results of the query, XML needs to be produced with the results.
List<Contact> conMobile = [SELECT MobilePhone, Dealer_Portal_Account_Created__c, account.discount_tier__c FROM Contact WHERE MobilePhone = :CID limit 1];
List<Contact> conPhone = [SELECT Phone, Dealer_Portal_Account_Created__c, account.discount_tier__c FROM Contact WHERE Phone = :CID limit 1];
List<Account> accPhone = [SELECT Phone, portalLoginCreatedEmailed__c, discount_tier__c FROM Account WHERE Phone = :CID limit 1];
List<Account> accFax = [SELECT Fax, portalLoginCreatedEmailed__c, discount_tier__c FROM Account WHERE Fax = :CID limit 1];
List<Contact> conFax = [SELECT Fax, Dealer_Portal_Account_Created__c, account.discount_tier__c FROM Contact WHERE Fax = :CID limit 1];
List<Account> accBillingPhone = [SELECT Billing_Contact_Phone__c, portalLoginCreatedEmailed__c, discount_tier__c FROM Account WHERE Billing_Contact_Phone__c = :CID limit 1];
Boolean conMobileMatched = false;
Boolean conPhoneMatched = false;
Boolean accPhoneMatched = false;
Boolean accBillingPhoneMatched = false;
Boolean accFaxMatched = false;
Boolean conFaxMatched = false;
//Checking Contact Mobile Phone
if (!conMobile.isEmpty()){
System.debug('Contact Mobile Phone: ' + conMobile);
conMobileMatched = true;
}
//Checking Contact Phone
else if (!conPhone.isEmpty()){
System.debug('Contact Phone: ' + conPhone);
conPhoneMatched = true;
}
//Checking Account Phone
else if (!accPhone.isEmpty()){
System.debug('Account Phone: ' + accPhone);
accPhoneMatched = true;
}
//Checking Account Billing aPhone
else if (!accBillingPhone.isEmpty()){
System.debug('Account Billing Phone: ' + accBillingPhone);
accBillingPhoneMatched = true;
//Checking Account Fax
else if (!accFax.isEmpty()){
System.debug('Account Fax Phone: ' + accFax);
accFaxMatched = true;
}
//Checking Contact Fax
else if (!conFax.isEmpty()){
System.debug('Contact Fax Phone: ' + conFax);
conFaxMatched = true;
}
else{
System.debug('Nothing');
}
}
}