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
samrat.1985@lntinfotechsamrat.1985@lntinfotech 

Urgent help reqd

public  List<Billing_Policy__c> policyList;

public String getPolicyNos()
{
    Integer i;
    String policyNos='';
    policyList= [select Policy_No__c from Billing_Policy__c where Name='7M3333'];
    if(policyList != null)
    {
       String[] policies= policyList.Policy_No__c;
        for(i=0; i<policies.size(); i++)
        {
            policyNos = policyNos + policies[i];
            Integer k=policies.size()-1;
            if(i != k)
            {
                policyNos += ', ';
            }
        }
    }
//    policyNos='12345AC';
    return policyNos;
   
}

 

Unable to get the error when i try to save the file....the line in red is where the error is.

 

Basically the billing policy has a list of policy numbers i want to put it in a string array which in turn will be displayed in a text box... Kindly help

Error: BillingContoller Compile Error: Initial term of field expression must be a concrete SObject: LIST<Billing_Policy__c> at line 28 column 27

 

 

Best Answer chosen by Admin (Salesforce Developers) 
samrat.1985@lntinfotechsamrat.1985@lntinfotech

public String getPolicyNos()
{
    Integer i;
    String policyNos='';
   
    policyList= [select Policy_No__c from Billing_Policy__c where Name='7555M'];
    if(policyList != null)
    {
      // String[] policies= policyList;
        for(i=0; i<policyList.size(); i++)
        {
            policyNos = policyNos + policyList[i].Policy_No__c;
            Integer k=policyList.size()-1;
            if(i != k)
            {
                policyNos += ', ';
            }
        }
    }
//    policyNos='12345AC';
    return policyNos;
   
}

 

Now it works...Thank you very much

All Answers

bob_buzzardbob_buzzard

Your policy list variable is a list (or array) of Billing_Policy__c, but you are treating it like a single instance.

 

If you are only expecting a single Billing_Policy__c with the name '7M3333', you can simply access the first element of the array, though its better practice to check that you did get a result,  e.g.

 

 policyList= [select Policy_No__c from Billing_Policy__c where Name='7M3333'];
    if ( (policyList != null) && (policyList.size()>0) )
    {
       String[] policies= policyList[0].Policy_No__c;
        for(i=0; i<policies.size(); i++)
        {
            policyNos = policyNos + policies[i];
            Integer k=policies.size()-1;
            if(i != k)
            {
                policyNos += ', ';
            }
        }
    }
//    policyNos='12345AC';
    return policyNos;
   
}

 However, I would expect you to still have problems with this line:

 

String[] policies= policyList[0].Policy_No__c;

 as a field on an sobject cannot be an array.

 

 

samrat.1985@lntinfotechsamrat.1985@lntinfotech

It is a list because on querying i will receive a list of policy numbers. but befor displaying it on the VF page i need to convert it to string right?

 

And yes the problem still exists

samrat.1985@lntinfotechsamrat.1985@lntinfotech

public String getPolicyNos()
{
    Integer i;
    String policyNos='';
   
    policyList= [select Policy_No__c from Billing_Policy__c where Name='7555M'];
    if(policyList != null)
    {
      // String[] policies= policyList;
        for(i=0; i<policyList.size(); i++)
        {
            policyNos = policyNos + policyList[i].Policy_No__c;
            Integer k=policyList.size()-1;
            if(i != k)
            {
                policyNos += ', ';
            }
        }
    }
//    policyNos='12345AC';
    return policyNos;
   
}

 

Now it works...Thank you very much

This was selected as the best answer