• SDFC FirstLeveler
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 5
    Replies
Hello Experts,

I am new to this, I've two objects one is StudentRecord__c and other one is TechCourse__c. The TechCourse__c is parent of the StudentRecord__c(lookup).

I just wanted to perform custom update through the update button, but getting an error :
"System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: StudentRecord__c.TechCourse__c"

Please review my code and help me. 
VF Page (StudentInsert):
<apex:page standardController="StudentRecord__c" extensions="StudentRecord">
  <apex:form >
  <apex:pageBlock title="Record A Student"> 
  <apex:PageBlockSection Title="Basic Details">
      <apex:inputField value="{!Student.TechCourse__c}"/> <!--TechCourse__c is custom lookup field in StudentRecord__c-->
      <apex:inputField value="{!Student.StudentName__c}"/>
      <apex:inputField value="{!Student.ParentName__c}"/>
      <apex:inputField value="{!Student.DOB__c}"/>
      <apex:inputField value="{!Student.Gender__c}"/>
  </apex:PageBlockSection>
  
  <apex:PageBlockSection Title="Contact Details">
      <apex:inputField value="{!Student.ContactNo__c}"/>
      <apex:inputField value="{!Student.EmailID__c}"/>
      <apex:inputField value="{!Student.Address__c}"/>
  </apex:PageBlockSection>
  
  <apex:pageBlockButtons >
      <apex:commandButton value="Save Student" action="{!saveStudent}"/>
      <apex:commandButton value="Save and New"/>
      <apex:commandButton Value="Cancel" action="{!cancel}"/>
  </apex:pageBlockButtons>
  
  </apex:pageBlock>
  
  </apex:form>
</apex:page>
VF PAGE: ViewStudent
<apex:page StandardController="StudentRecord__c" extensions="StudentRecord" action="{!viewStudent}">
  <apex:form >
          <apex:pageBlock title="Record A Student"> 
          <apex:PageBlockSection Title="Basic Details">
              
              <apex:outputField value="{!Student.TechCourse__c}"/>
              
              <apex:outputField value="{!Student.StudentName__c}"/>
              <apex:outputField value="{!Student.ParentName__c}"/>
              <apex:outputField value="{!Student.DOB__c}"/>
              <apex:outputField value="{!Student.Gender__c}"/>
          </apex:PageBlockSection>
          
          <apex:PageBlockSection Title="Contact Details">
              <apex:outputField value="{!Student.ContactNo__c}"/>
              <apex:outputField value="{!Student.EmailID__c}"/>
              <apex:outputField value="{!Student.Address__c}"/>
          </apex:PageBlockSection>
                                     
          <apex:pageBlockButtons > 
                    <apex:commandButton Value="Update" action="{!EditStudent}"/>
            </apex:pageBlockButtons>   
                                                   
      </apex:pageBlock>
    </apex:form> 
</apex:page>

Controller (StudentRecord):
public class StudentRecord {
    
    public StudentRecord__c Student{set;get;}

    public StudentRecord(ApexPages.StandardController controller) {
        Student= (StudentRecord__c)controller.getRecord();    

    }
    
    public PageReference saveStudent(){
         
         insert Student;
         
         pageReference StuView = new PageReference(Page.ViewStudent.getUrl()+'?Id='+Student.Id);
         StuView.setRedirect(true);
         return StuView;
 
    }       
 public void viewStudent(){
        String id = ApexPages.currentPage().getParameters().get('Id');
        if(id != null){
            Student= [select Id, TechCourse__c, StudentName__c, ParentName__c, DOB__c, Gender__c, ContactNo__c, EmailID__c, Address__c from StudentRecord__c 
            where Id = :id];
              }
    } 
    
 //this is the function i want to run 
public PageReference EditStudent(){
        String id = ApexPages.currentPage().getParameters().get('Id');
        if(id != null){
            Student= [select Id, TechCourse__c, StudentName__c, ParentName__c, DOB__c, Gender__c, ContactNo__c, EmailID__c, Address__c from StudentRecord__c 
            where Id = :id];
              }
         else{return null;}
         pageReference StuView = new PageReference(Page.StudentInsert.getUrl()+'?Id='+Student.Id);
         StuView.setRedirect(true);
         return StuView;
         
    } 
 


}

Thanks in advance.
 
 
public class particular {
    public string products    {get;set;}
    public Particular__c unit_price {get;set;}
    public Particular__c quantity   {get;set;}
    public Particular__c total {get;set;}
    public invoice__c invoice{get;set;}
    public list<particular__c> lstPar {get;set;}
    
    public particular(ApexPages.StandardController controller) {
    lstPar= [select Invoice__r.Invoice__c, Particular_Name__r.Product, Line_Total__c, 
    Quantity__c, Unit_Price__c from Particluar__c];    
    }
}

Hi Experts,
In above code i have two custom objects:

Particulars__c and Invoice__c.
I want to get records of the particluar__c and it is having MD relationship with invoice and lookup with Product.

Hi experts,

I am trying to perform the dynamic search in account object but getting error while I input in respective fields: 

"System.QueryException: unexpected token: =
Error is in expression '{!desiredSearch}' in component <apex:commandButton> in page happysearchpage: Class.HappySearch.desiredSearch: line 18, column 1"
Class.HappySearch.desiredSearch: line 18, column 1

Please review my code and suggest me solution. 
Thanks

My Controller Code:
public class HappySearch {
    public list <Account> a {set;get;}
    public string aName     {set;get;}
    public string aType     {set;get;}
    
    public void desiredSearch(){
                        string Dsearch='Select Name, Type From Account';
                        if ((aName!=Null && aName!= '') && (aType!=''&& aType!=Null )){
                            Dsearch= Dsearch+ 'where name=\' '+aName+' \' and type=\' '+aType+' \'';}
                         else {
                            if(aName!=Null && aName!= ''){
                                    Dsearch= Dsearch+ 'where name=\' '+aName+' \'';} 
                                   else{
                                     if(aType!=Null && aType!=''){
                                         Dsearch= Dsearch+ 'where type=\' '+aType+' \'';}
                                       }
                                }
                          a= Database.query(Dsearch);
                        } 
                }

VF Page Code:
<apex:page controller="HappySearch" >
<apex:form >
    
    <apex:pageBlock title="Search">
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel Value="Name"/>
                <apex:inputText value="{!aName}"/>  
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel Value="Type"/>
                <apex:inputText value="{!aType}"/>  
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection> 
    
       <apex:pageBlockButtons location="Bottom">
           <apex:commandButton value="DSearch" Action="{!desiredSearch}"/>
       </apex:pageBlockButtons>
    </apex:pageBlock>
       
    <apex:pageBlock title="Search Result" rendered="(! !ISNULL(a))" >
       <apex:pageBlockTable value="{!a}" var="b">
       <apex:column value="{!b.Name}"/>
       <apex:column Value="{!b.Type}"/>
       </apex:pageBlockTable>    
    </apex:pageBlock>
     
</apex:form>
</apex:page>

P.S. it worked well if no inputs given to repective fields.   ​

 
Controller Class :

public Class a {
    public integer userinput{get; set;}
        
       public void getclickMe(){
        string n;
        if (userinput> 0){
         n= 'No is Positive'; 
        }
        else if (userinput< 0){
        n= 'No is Negative';         
        }
        else{
          n='Number is zero';
        }
    }
}


VFPage:

<apex:page controller="a">
<apex:form >
<apex:pageBlock title=" Take Input">
<apex:pageBlockSection >
<apex:outputLabel value="Enter Number" />
<apex:inputText value="{!userinput}" />
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:commandButton value="Find" action="{!getclickMe}"/>


<apex:outputPanel >
<apex:outputText value="{!clickMe}">
</apex:outputText>
</apex:outputPanel>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

 
The button will search account records if I dont put any values for any
VF page

<apex:page controller="DynaSearch" >
<apex:form >
    <apex:pageBlock title="Search">
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel Value="Name"/>
                <apex:inputText value="{!aName}"/>  
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel Value="Type"/>
                <apex:inputText value="{!aType}"/>  
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection> 
    
       <apex:pageBlockButtons location="Bottom">
       <apex:commandButton value="Search" Action="{!search}"/>
       <apex:commandButton value="Desired Search" Action="{!desiredSearch}"/>
       </apex:pageBlockButtons>
       </apex:pageBlock>
       
       <apex:pageBlock title="Search Result" rendered="{! !ISNull(a)}">
    <apex:pageBlockTable value="{!a}" var="b">
    <apex:column value="{!b.Name}"/>
     <apex:column Value="{!b.Type}"/>
    </apex:pageBlockTable>    
    </apex:pageBlock>
     
</apex:form>
</apex:page>


Controller Class:



public class DynaSearch {
    public list <Account> a {set;get;}
    public string aName {set;get;}
    public string aType {set;get;}
    
    public void search(){
        a=[SELECT Name, Type from Account where name=:aName and Type=:aType];
        
    }
    public void desiredSearch(){
          string Dsearch;
        if((aName= Null && aName= '') && (aType= Null && aType='')){
                Dsearch ='SELECT Name, Type from Account';
        } 
        
       else if ((aName!=Null && aName!= '') && (aType!=Null && aType!='')){
             Dsearch= 'SELECT name, Type from Account where name=\' '+aName+' \' and type=\' '+aType+' \''; 
         }
   
        else {
            	if(aName!=Null && aName!= ''){
             		Dsearch= 'SELECT name, Type from Account where name=\' '+aName+' \'';  
                } else{
                    	if(aType!=Null && aType!=''){
            				Dsearch= ' SELECT name, Type from Account where type=\' '+aType+' \'';
                        	}
                		}
         }
           
         		a= Database.query(Dsearch);
    } 

}

input test fields.
public class MyFirstProgram {
    public void sfClass() {
        for(Integer i=1; i<=5; i++){
            for(Integer j=1; j<=5; j++){
                if(j<=i){
                    System.debug('*');
                    else{
                        system.debug(' ');
                    }
                }
            }
        }
    }
}
MyFirstProgram Program =new MyFirstProgram();
Program.sfClass(); 
Hi Experts,
I am creating an app (through point and click), in which user gets register. Is it possible to give login credential to user through this app so s/he can acces the app or I need to create user only from Standard Admin> User Management to provide login to my salesforce app. Please help.
 
Hi Experts,
I am creating an app (through point and click), in which user gets register. Is it possible to give login credential to user through this app so s/he can acces the app or I need to create user only from Standard Admin> User Management to provide login to my salesforce app. Please help.
 
Hi experts,

I am trying to perform the dynamic search in account object but getting error while I input in respective fields: 

"System.QueryException: unexpected token: =
Error is in expression '{!desiredSearch}' in component <apex:commandButton> in page happysearchpage: Class.HappySearch.desiredSearch: line 18, column 1"
Class.HappySearch.desiredSearch: line 18, column 1

Please review my code and suggest me solution. 
Thanks

My Controller Code:
public class HappySearch {
    public list <Account> a {set;get;}
    public string aName     {set;get;}
    public string aType     {set;get;}
    
    public void desiredSearch(){
                        string Dsearch='Select Name, Type From Account';
                        if ((aName!=Null && aName!= '') && (aType!=''&& aType!=Null )){
                            Dsearch= Dsearch+ 'where name=\' '+aName+' \' and type=\' '+aType+' \'';}
                         else {
                            if(aName!=Null && aName!= ''){
                                    Dsearch= Dsearch+ 'where name=\' '+aName+' \'';} 
                                   else{
                                     if(aType!=Null && aType!=''){
                                         Dsearch= Dsearch+ 'where type=\' '+aType+' \'';}
                                       }
                                }
                          a= Database.query(Dsearch);
                        } 
                }

VF Page Code:
<apex:page controller="HappySearch" >
<apex:form >
    
    <apex:pageBlock title="Search">
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel Value="Name"/>
                <apex:inputText value="{!aName}"/>  
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel Value="Type"/>
                <apex:inputText value="{!aType}"/>  
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection> 
    
       <apex:pageBlockButtons location="Bottom">
           <apex:commandButton value="DSearch" Action="{!desiredSearch}"/>
       </apex:pageBlockButtons>
    </apex:pageBlock>
       
    <apex:pageBlock title="Search Result" rendered="(! !ISNULL(a))" >
       <apex:pageBlockTable value="{!a}" var="b">
       <apex:column value="{!b.Name}"/>
       <apex:column Value="{!b.Type}"/>
       </apex:pageBlockTable>    
    </apex:pageBlock>
     
</apex:form>
</apex:page>

P.S. it worked well if no inputs given to repective fields.   ​

 
Controller Class :

public Class a {
    public integer userinput{get; set;}
        
       public void getclickMe(){
        string n;
        if (userinput> 0){
         n= 'No is Positive'; 
        }
        else if (userinput< 0){
        n= 'No is Negative';         
        }
        else{
          n='Number is zero';
        }
    }
}


VFPage:

<apex:page controller="a">
<apex:form >
<apex:pageBlock title=" Take Input">
<apex:pageBlockSection >
<apex:outputLabel value="Enter Number" />
<apex:inputText value="{!userinput}" />
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:commandButton value="Find" action="{!getclickMe}"/>


<apex:outputPanel >
<apex:outputText value="{!clickMe}">
</apex:outputText>
</apex:outputPanel>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

 
The button will search account records if I dont put any values for any
VF page

<apex:page controller="DynaSearch" >
<apex:form >
    <apex:pageBlock title="Search">
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel Value="Name"/>
                <apex:inputText value="{!aName}"/>  
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel Value="Type"/>
                <apex:inputText value="{!aType}"/>  
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection> 
    
       <apex:pageBlockButtons location="Bottom">
       <apex:commandButton value="Search" Action="{!search}"/>
       <apex:commandButton value="Desired Search" Action="{!desiredSearch}"/>
       </apex:pageBlockButtons>
       </apex:pageBlock>
       
       <apex:pageBlock title="Search Result" rendered="{! !ISNull(a)}">
    <apex:pageBlockTable value="{!a}" var="b">
    <apex:column value="{!b.Name}"/>
     <apex:column Value="{!b.Type}"/>
    </apex:pageBlockTable>    
    </apex:pageBlock>
     
</apex:form>
</apex:page>


Controller Class:



public class DynaSearch {
    public list <Account> a {set;get;}
    public string aName {set;get;}
    public string aType {set;get;}
    
    public void search(){
        a=[SELECT Name, Type from Account where name=:aName and Type=:aType];
        
    }
    public void desiredSearch(){
          string Dsearch;
        if((aName= Null && aName= '') && (aType= Null && aType='')){
                Dsearch ='SELECT Name, Type from Account';
        } 
        
       else if ((aName!=Null && aName!= '') && (aType!=Null && aType!='')){
             Dsearch= 'SELECT name, Type from Account where name=\' '+aName+' \' and type=\' '+aType+' \''; 
         }
   
        else {
            	if(aName!=Null && aName!= ''){
             		Dsearch= 'SELECT name, Type from Account where name=\' '+aName+' \'';  
                } else{
                    	if(aType!=Null && aType!=''){
            				Dsearch= ' SELECT name, Type from Account where type=\' '+aType+' \'';
                        	}
                		}
         }
           
         		a= Database.query(Dsearch);
    } 

}

input test fields.