• Ankush Agarwal
  • NEWBIE
  • 25 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 7
    Replies
<apex:page controller="Hospital" >
<apex:form >
<apex:pageBlock >
  <apex:pageMessages id="showmsg"></apex:pageMessages>  
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
  Hospital Name : 
<apex:inputField value="{!hosp.Name}"/>  
</apex:pageBlockSectionItem>
    
 <apex:pageBlockSectionItem >
Account Name :  
 <apex:inputField value="{!hosp.Account__c}"/>
</apex:pageBlockSectionItem>  
</apex:pageBlockSection>   
  
    <apex:pageBlockButtons >
    
<apex:commandButton action="{!insertNewItem}" value="Save" rerender="showmsg"/>   

</apex:pageBlockButtons>
    
<apex:pageBlockTable value="{! insertedrecord }" var="ct" id="mainSection">
    <apex:column headerValue="Hospital Name">"{! ct.Name }"</apex:column>
    <apex:column headerValue="Account Name">"{! ct.Account__c }"</apex:column>
</apex:pageBlockTable>    

</apex:pageBlock>
</apex:form>
</apex:page>
 
public class Hospital{

    public Hospital__c hosp{get;set;}
    public Hospital__c insertedrecord{get;set;}
 public Hospital()
    {
        hosp = new Hospital__c();
    }
    
  public void insertNewItem() {
if(hosp.Name == NULL || hosp.Name == '' )
{
   ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Please enter'));   
}
 else
 {     
      insert hosp;
      id insertedrecordid = hosp.Id;
      insertedrecord = [Select Name, Account__c  from Hospital__c where Id = :insertedrecordid Limit 1];
     
 }   
  }
}



Insert failed. First exception on row 0 with id a0B2w000000hYugEAE; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
Error is in expression '{!insertNewItem}' in component <apex:commandButton> in page task1hospital: Class.Hospital.insertNewItem: line 17, column 1
 

I am getting above error, Please help me

Thanks in Advance

<apex:page controller="Hospital" >
<apex:form >
<apex:pageBlock >
  <apex:pageMessages id="showmsg"></apex:pageMessages>  
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
  Hospital Name : 
<apex:inputField value="{!hosp.Name}"/>  
</apex:pageBlockSectionItem>
    
 <apex:pageBlockSectionItem >
Account Name :  
 <apex:inputField value="{!hosp.Account__c}"/>
</apex:pageBlockSectionItem>  
</apex:pageBlockSection>   
  
    <apex:pageBlockButtons >
    
<apex:commandButton action="{!insertNewItem}" value="Save" rerender="showmsg"/>   

</apex:pageBlockButtons>
    
<apex:pageBlockTable value="{! insertedrecord }" var="ct" id="mainSection">
    <apex:column headerValue="Hospital Name">"{! ct.Name }"</apex:column>
    <apex:column headerValue="Account Name">"{! ct.Account__c }"</apex:column>
</apex:pageBlockTable>    

</apex:pageBlock>
</apex:form>
</apex:page>
 
public class Hospital{

    public Hospital__c hosp{get;set;}
    public Hospital__c insertedrecord{get;set;}
 public Hospital()
    {
        hosp = new Hospital__c();
    }
    
  public void insertNewItem() {
if(hosp.Name == NULL || hosp.Name == '' )
{
   ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Please enter'));   
}
 else
 {     
      insert hosp;
      id insertedrecordid = hosp.Id;
      insertedrecord = [Select Name, Account__c  from Hospital__c where Id = :insertedrecordid Limit 1];
     
 }   
  }
}



Insert failed. First exception on row 0 with id a0B2w000000hYugEAE; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
Error is in expression '{!insertNewItem}' in component <apex:commandButton> in page task1hospital: Class.Hospital.insertNewItem: line 17, column 1
 

I am getting above error, Please help me

Thanks in Advance

Created Apex Class and Lightning page component but it's not showing up under custom components when I try to "edit page". Looking for some help to see where I went wrong.

Below is what I have:
Apex Class
User-added image
Lightning component bundle (component, controller, helper)
User-added imageUser-added imageUser-added imageUser-added image
Hey all - I've researched enough to understand that what I need to do can only be done in Visualforce: displaying a text field based on picklist options.

Basically, I have 5 fields "RP 1, RP 2, RP 3, RP 4, RP 5" in a custom object "Staff Development" and they all are picklists that have the same options for answers (the 34 clifton strengths - basically I am trying to give everyone a place to identify their top 5 strenghts on a page).

Based on the answers in ALL 5 of these fields collectively, I want to display further information. So if the answers in the picklists include (order doesn't matter) Adaptability, individluzation, woo, empathy, and developer - then there needs to be 5 text fields (with default values) named Adaptability, Individualization, Woo, Empathy, and Developer that pop up that shows the description for each of those answers.

Again, doesn't matter which of the 5 "RP" fields is chosen that includes one of those strengths, if the picklist choice is chosen in any of the 5 picklist fields, that text field appears (normally hidden) and displays the information. 

Any help appreciated!