+ Start a Discussion
madhu l 1madhu l 1 

hi guys please find this error below code


[Error] Error: Compile Error: Initial term of field expression must be a concrete SObject: String at line 6 column 12


public class CountryClub {

    public String imageURL{ get; set; }

    public PageReference Upload() {
           imageURL.AuthorId = UserInfo.getUserId(); 
           imageURL.FolderId = UserInfo.getUserId(); // put it in running user's folder 
             try { 
              insert imageURL; 
               } catch (DMLException e) { 

               ApexPages.addimage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file')); 
              }    
//Add more logic here
        return null;
    
   }

    public PageReference Browse() {

imageURL.AuthorId = UserInfo.getUserId(); 
          imageURL.FolderId = UserInfo.getUserId(); // put it in running user's folder 
             try { 
              insert imageURL; 
               } catch (DMLException e) { 

               ApexPages.addimage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
}
    //Add more logic here
        return null;
    

}
}
Amit Chaudhary 8Amit Chaudhary 8
Hi Madu,

Issue in your code is that you are trying perform the DML (insert) on String. That is not possible. You can perform the DML on Sobject only. means on standard object or custom object.

Can you please confirm me on  which object you want to insert ?
If you are trying ton insert the document object then please reffer below post. I hope that will help u
http://developer.force.com/cookbook/recipe/uploading-a-document-using-visualforce-and-a-custom-controller
<apex:page controller="FileUploadController">
  <apex:sectionHeader title="Visualforce Example" subtitle="File Upload Example"/>
 
  <apex:form enctype="multipart/form-data">
    <apex:pageMessages />
    <apex:pageBlock title="Upload a File">
 
      <apex:pageBlockButtons >
        <apex:commandButton action="{!upload}" value="Save"/>
      </apex:pageBlockButtons>
 
      <apex:pageBlockSection showHeader="false" columns="2" id="block1">
 
        <apex:pageBlockSectionItem >
          <apex:outputLabel value="File Name" for="fileName"/>
          <apex:inputText value="{!document.name}" id="fileName"/>
        </apex:pageBlockSectionItem>
 
        <apex:pageBlockSectionItem >
          <apex:outputLabel value="File" for="file"/>
          <apex:inputFile value="{!document.body}" filename="{!document.name}" id="file"/>
        </apex:pageBlockSectionItem>
 
        <apex:pageBlockSectionItem >
          <apex:outputLabel value="Description" for="description"/>
          <apex:inputTextarea value="{!document.description}" id="description"/>
        </apex:pageBlockSectionItem>
 
        <apex:pageBlockSectionItem >
          <apex:outputLabel value="Keywords" for="keywords"/>
          <apex:inputText value="{!document.keywords}" id="keywords"/>
        </apex:pageBlockSectionItem>
 
      </apex:pageBlockSection>
 
    </apex:pageBlock>
  </apex:form>
</apex:page>
 
public with sharing class FileUploadController {
 
  public Document document {
    get {
      if (document == null)
        document = new Document();
      return document;
    }
    set;
  }
 
  public PageReference upload() {
 
    document.AuthorId = UserInfo.getUserId();
    document.FolderId = UserInfo.getUserId(); // put it in running user's folder
 
    try {
      insert document;
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
      return null;
    } finally {
      document.body = null; // clears the viewstate
      document = new Document();
    }
 
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully'));
    return null;
  }
 
}
In your case in hope can try below code:-
public class CountryClub 
{
    public Document imageURL{ get; set; }
	
	public CountryClub()
	{
		imageURL= new Document();
	}
    
	public PageReference Upload() 
	{
           imageURL.AuthorId = UserInfo.getUserId(); 
           imageURL.FolderId = UserInfo.getUserId(); // put it in running user's folder 
             try { 
              insert imageURL; 
               } catch (DMLException e) { 
					ApexPages.addimage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file')); 
              }    
			//Add more logic here
        return null;
   }

    public PageReference Browse() 
	{
		  imageURL.AuthorId = UserInfo.getUserId(); 
          imageURL.FolderId = UserInfo.getUserId(); // put it in running user's folder 
             try { 
              insert imageURL; 
               } catch (DMLException e) { 

               ApexPages.addimage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
			}
		//Add more logic here
        return null;
	}
}
Please let us know if this will help you

Thanks
Amit Chaudhary
geeta garggeeta garg
hi
can you explain about "document.AuthorId = UserInfo.getUserId(); document.FolderId = UserInfo.getUserId(); ".
you are putting user id in author id and folder id both.
thanks,
geeta garg