0

i am trying to add one button in lead detail page layout.on clicking on this button i want show a visual force page showing custom object details.my custom object is tractor__c.so far i am trying this code

<apex:page docType="html-5.0" standardController="Lead" extensions="LeadTractorExtension">
<style>
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>



    <div class="row">
        <div class="col-sm-12">
            <div class="form-group">
            <h3>Search for Tractor</h3>
            </div>
            <div class="col-sm-12 form-group">
                <apex:form >
                <apex:pageBlock >



    <div class="col-sm-3">
        <label>Tractor Make</label>

        <apex:inputField value="{!tractor .Manufacturer__c}"/>
     </div> 
     <div class="col-sm-3">
        <label>Tractor Model</label>

         <apex:inputField value="{!tractor.Model_Name__c }"/>
     </div>
     <div class="col-sm-3">
        <label>Deck Size</label>

         <apex:inputField value="{!tractor.Deck__c }"/>
    </div>
    <div class="col-sm-3">
        <label>Rake Model</label>

         <apex:inputField value="{!tractor.Rake_Model__c }"/>
    </div>


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

        </div>  

            <div class="row">
                <div class="col-sm-offset-4 ">
            <button>Check For Availebility</button>
            </div>
            </div>
    </div>
  </div>

and for my extension class is like

public class LeadTractorExtension {
public  Tractor__c tractor{get;set;}



public LeadTractorExtension(ApexPages.StandardController stdController) {
    this.tractor = (Tractor__c)stdController.getRecord();
   getTractorDetails(); 
}
public Tractor__c getTractorDetails(){
    return tractor;
}

} i am getting error like Invalid conversion from runtime type Lead to Tractor__c .if i change standard controller name to tractor__c .page will work .but this page wont list in lead page layout.In Lead object TractorInfo__c is the lookup field.can any one help to solve this issue

1 Answer 1

0

standardController="Lead" means that what you get from stdController.getRecord() will also be a Lead. You cannot cast one type of sObject into another type, which is what causes the runtime error you experienced.

You probably meant to create a new record:

public Tractor__c tractor { get; set; }
// we use this in case we need the lead record later.
private ApexPages.StandardController stdController;

public LeadTractorExtension(ApexPages.StandardController stdController) {
  tractor = new Tractor__c();
  this.stdController = stdController;
}

It's also possible you meant to query a record or something else, but there's not enough detail in your question to know for sure.

3
  • @sfdcfox.thanks for your reply.its working for me.so what my intention is to search for a tractor by getting data from three input field that i mentioned in the code.i need to query with these details on tractor__c and need to display the records if it is availeble
    – ebk
    Commented Sep 15, 2018 at 5:42
  • @ebk Yes, so you need a dynamic SOQL query, an apex:commandButton, and an apex:dataTable (presumably, since you're using Bootstrap). I'm not going to be able to write your entire project for you, but do feel free to ask more questions if you get stuck.
    – sfdcfox
    Commented Sep 15, 2018 at 5:59
  • .thanks for your advice.i am able to list all the available tractors based on the input fields.now my last requirement is ,can i select any one of the tractor from my list and show in my detail page where a i have a field called tractor.i don't know whether its possible or not bcz it is a vf page that is opening on a button click.
    – ebk
    Commented Sep 15, 2018 at 7:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .