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
MaggieSumitMaggieSumit 

plz check my code am getting this error : Entity is not org-accessible

public with sharing class contollertest {

    Public id Current_le_Id;
    public Boolean isEdit { set; get;}
    public List<Question__c> lstQuestion {set;get;}
    public contollertest (ApexPages.StandardController controller) {
        Current_le_Id = controller.getRecord().id;
        isEdit = false;
        lstQuestion = New List<Question__c>();
        for(Lead le:[select id,name,(select id,Name,Email__c from Questions__r) from lead where id=:Current_le_Id]){
           for(Question__c con:le.Question__c)
               lstQuestion.add(con);
        }
    }
    public void editProcess(){
        isEdit = true;
    }
    public  void save(){
        
        if(lstQuestion.size() > 0){
            upsert lstQuestion;
            lstQuestion.clear();
        }
        
        for(Lead le:[select id,name,(select id,Name,Email__c from Questions__r) from lead where id=:Current_le_Id]){
           for(Question__c con:le.Question__c)
               lstQuestion.add(con);
        }
        isEdit = false;
    }
    public void addQuestion(){
        lstQuestion.add(new Question(leadId = Current_le_Id));
        isEdit = true;
    }
}
<!--Page-->
<apex:page standardController="Account" extensions="contrllr">
  <apex:form >
    <apex:pageblock id="pgb">
    <apex:pageBlockButtons >
        <apex:commandButton value="edit" action="{!editProcess}" rendered="{!Not(isEdit)}" reRender="pgb"/>
        <apex:commandButton value="save" action="{!save}" rendered="{!isEdit}" reRender="pgb"/>        
        </apex:pageBlockButtons>
       <apex:pageBlockTable value="{!lstQuestion}" var="val" rendered="{!Not(isEdit)}">
         <apex:column value="{!val.Name}"/>
         <apex:column value="{!val.Email__c}"/>
       </apex:pageBlockTable> 
       <apex:outputPanel rendered="{!Not(isEdit)}">
           <apex:commandButton action="{!addQuestion}" value="Add Contact" reRender="pgb"/>
       </apex:outputPanel>
        <apex:pageBlockTable value="{!lstQuestion}" var="val" rendered="{!(isEdit)}">
         <apex:column headerValue="FirstName">
             <apex:inputField value="{!val.Name}"/>
         </apex:column>
          <apex:column headerValue="Email">
             <apex:inputField value="{!val.Email__c}"/>
         </apex:column>
         <apex:column >
             <apex:inputField value="{!val.Email__c}"/>
         </apex:column>
       </apex:pageBlockTable> 
    </apex:pageblock>
  </apex:form>
</apex:page>
Best Answer chosen by MaggieSumit
Abhilash Mishra 13Abhilash Mishra 13

Hi Sumit,
This is Quite confusing.

First of all I would like to tell you that, You can not Use ID as you have written above. It means you are trying to reference id of Question__c type record but your ID value is of a lead  type record (they always starts with 00Q). Hence it is giving you invalid ID value Error.

Now for the other issue. Please go to the fields page of Question__c. Check The API name Of  LeadID. use that name as apiname=Current_lead_Id. 

this will solve all the issues I guess. Or please share a snapshot of fields of Question__c.

I will be happy to help.

Regards
Abhilash Mishra

All Answers

sandeep@Salesforcesandeep@Salesforce
Hi Sumit,

These type of erorr comes at compile time. It might be possibe you are using some api which does not exist in org or please try to change Api verison of your class and page to higher one. 

Here is one more helpful link where simliar question was posted.
http://salesforce.stackexchange.com/questions/4599/efficient-way-to-find-error-causing-save-error-entity-is-not-org-accessible

Thanks
Sandeep Singhal
http://www.codespokes.com/
Naresh YadavNaresh Yadav
Hi Sumit,

See the bold line. And use the below code.

public with sharing class contollertest {

    Public id Current_le_Id;
    public Boolean isEdit { set; get;}
    public List<Question__c> lstQuestion {set;get;}
    public contollertest (ApexPages.StandardController controller) {
        Current_le_Id = controller.getRecord().id;
        isEdit = false;
        lstQuestion = New List<Question__c>();
        for(Lead le:[select id,name,(select id,Name,Email__c from Questions__r) from lead where id=:Current_le_Id]){
           for(Question__c con:le.Question__r)    //  Use le.Question__r instead of le.Question__c
               lstQuestion.add(con);
        }
    }
    public void editProcess(){
        isEdit = true;
    }
    public  void save(){
        
        if(lstQuestion.size() > 0){
            upsert lstQuestion;
            lstQuestion.clear();
        }
        
        for(Lead le:[select id,name,(select id,Name,Email__c from Questions__r) from lead where id=:Current_le_Id]){
           for(Question__c con:le.Question__c)
               lstQuestion.add(con);
        }
        isEdit = false;
    }
    public void addQuestion(){
        lstQuestion.add(new Question(leadId = Current_le_Id));
        isEdit = true;
    }
}


Let me know if it helps you out.
 
Rohit K SethiRohit K Sethi
I had some minor typo in my program that led me to the same error. Not sure if it's the same case with you. I forgot to add __c when calling a custom object and got the same error. Hope this helps!
MaggieSumitMaggieSumit
Thanks Naresh Yadav, it stil giving same erro>>> there are something worng is these code
When i using a coid for addQuestion its showing that message 

 public void addQuestion(){
        lstQuestion.add(new Question(leadId = Current_le_Id));
        isEdit = true;
    }
Abhilash Mishra 13Abhilash Mishra 13
Hi sumit , As I can see  Question is a custom object.  You need to use __C here.

 lstQuestion.add(new Question(leadId = Current_le_Id));

replace it with  lstQuestion.add(new Question__C(leadId = Current_le_Id));

Regards
Abhilash 
MaggieSumitMaggieSumit
Thanks Abhilash I have already makes that changes if i am using Question__c then I got a error: Invalid field LeadId for SObject Question__c
and if i use Question then i got error: Entity is not org-accessible.
 
Abhilash Mishra 13Abhilash Mishra 13
Hi Sumit,
I think LeadID is also a custom field you made of lookup type  for lead. Please Use LeadID__C 

Regards
Abhilash
Rohit K SethiRohit K Sethi
Hi sumit ,

As Abhilash give suggestion that is right but there is little bit mistake that is the field name "leadId"  you need to append "__c" after the field because it is a custom field.

If after the appending the "__C" if your code again give error then check the API name of the field leadId in Question__C Object on which you are assigning Current_le_Id.

Thanks.
MaggieSumitMaggieSumit
I tried with that i got unsuccess, Now i change leadId to Id only then its work good,
 
lstQuestion.add(new Question__c(id = Current_lead_Id));

But when i press AddQuestion Button on VF page i got this error message:


System.TypeException: Invalid id value for this SObject type: 00Q2800000HeVCNEA3
Error is in expression '{!addQuestion}' in component <apex:commandButton> in page jaima: Class.contollertest.addQuestion: line 32, column 1
Class.contollertest.addQuestion: line 32, column 1
Abhilash Mishra 13Abhilash Mishra 13

Hi Sumit,
This is Quite confusing.

First of all I would like to tell you that, You can not Use ID as you have written above. It means you are trying to reference id of Question__c type record but your ID value is of a lead  type record (they always starts with 00Q). Hence it is giving you invalid ID value Error.

Now for the other issue. Please go to the fields page of Question__c. Check The API name Of  LeadID. use that name as apiname=Current_lead_Id. 

this will solve all the issues I guess. Or please share a snapshot of fields of Question__c.

I will be happy to help.

Regards
Abhilash Mishra

This was selected as the best answer
MaggieSumitMaggieSumit
User-added image
MaggieSumitMaggieSumit
Thanks to all of you for continuous helping on this topic.
MaggieSumitMaggieSumit
Thanks Abhilash Mishra 13, Rohit K Sethi