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
bpl3792bpl3792 

Save error: Initial term of field expression must be a concrete SObject

I'm trying to build a class that imports a .csv file. Everything works fine except for one field I need to import into. That field is a lookup for another object and I don't want to overwrite data in the object being looked up to...just the field making the lookup. ICCN.Code_Master_Reference__r = CM.id; is the culprit but I'm at a loss as to how I should do this. 

 

public with sharing class mc_CCNCodeImport {

    public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    public string PSAmt {get;set;}
    public string PSReimAmt {get;set;}
    public Carrier_Contract_Negotiation__c CCN {get;set;}
    public String Delquery;
    public  List<CCN_Code_Entry__c> CCNCodestoupload {get;set;}
	public  List<Code_Master__c> CM {get;set;}
      
    String[] filelines = new String[]{};
   
    
   public mc_CCNCodeImport(ApexPages.StandardController controller){
    	this.CCN=(Carrier_Contract_Negotiation__c)controller.getRecord();
    }
   
 
    public Pagereference ReadFile()
    {
    	
    	Delquery='SELECT Code_Master_Reference__c, Pricesheet_Amount__c, Reimbursement_Amount__c FROM CCN_Code_Entry__c WHERE Carrier_Contract_Negotiation__c= \''+CCN.id+ '\'';
    	
    	CCN_Code_Entry__c[] doomedCodes=Database.query(Delquery);
    	
    	Database.Deleteresult[] DR_Dels=Database.delete(doomedCodes);
  
    	
        nameFile=contentFile.toString();
        filelines = nameFile.split('\n');
        CCNCodestoupload = new List<CCN_Code_Entry__c>();
		CM=new list<Code_Master__c>();
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
            
           	CCN_Code_Entry__c ICCN = new CCN_Code_Entry__c();

           	ICCN.Carrier_Contract_Negotiation__c=CCN.id;
           
           string query='SELECT id FROM Code_Master__c WHERE Name= \''+inputvalues[0]+ '\'';
           CM=Database.query(query);

           
           
           String PSReimAmt=String.valueOf(ICCN.Reimbursement_Amount__c);
       
             
           	ICCN.Code_Master_Reference__r = CM.id;
           	PSReimAmt=inputvalues[1];
            
            ICCN.Reimbursement_Amount__c=double.valueOf(PSReimAmt);
            

            system.debug(CCNCodestoupload.add(ICCN));
        }
        try{
        insert CCNCodestoupload;
        }
        catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
            ApexPages.addMessage(errormsg);
        }    
        return null;
    }
    
    public List<CCN_Code_Entry__c> getuploadedCCNCodes()
    {
        if (CCNCodestoupload!= NULL)
            if (CCNCodestoupload.size() > 0)
                return CCNCodestoupload;
            else
                return null;                    
        else
            return null;
    }


}

 

dmchengdmcheng

Can you give some details about these objects and their relationships?  It seems like ICCN.Code_Master_Reference__c = CM.id should do what you need.  I don't understand why you are trying to manipulate  __r, since that is the relationship and not a field or object.

bpl3792bpl3792

Sorry, that's supposed to be ICCN.Code_Master_Reference__c . Code_Master_Reference__c looks up to another object called Code_Master__c from CCN_Code_Entry__c.

dmchengdmcheng

So that is your solution, right?  if you want "to overwrite data in ... just the field making the lookup", then you use 

 

ICCN.Code_Master_Reference__c = CM.Id

 

like you have already.

bpl3792bpl3792

I meant that I didn't mean to leave it as ICCN.Code_Master_Reference__r. I figured it should be ICCN.Code_Master_Reference__c I just never changed it however I am still getting the same error after I changed it "Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Code_Master__c> at line 51 column 44 "

dmchengdmcheng

ICCN is a single record, but CM is a list.  CM.Id is not a valid expression.

bpl3792bpl3792

So how do you extract the id from the soql query then?

dmchengdmcheng

CM is a List, so you have to iterate through each record in the list.  But there is something wrong with your code logic.  Why is ICCN a single record and CM a list of records?