• bovis
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

Hi,

 

How do you create 2 custom objects using Visualforce and then associate one as a lookup field in the other? E.g. Lets use the recruiter application. I want someone to create themselves as a candidate and then apply for a job at the same time.

 

Here's the apex

<apex:page controller="ApplicationCreateController">
  <apex:sectionHeader title="Visualforce Example" subtitle="Create a Job Application"/>
  <apex:form >
    <apex:pageMessages /> <!-- this is where the error messages will appear -->
    <apex:pageBlock title="Candidate Info">
      <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection showHeader="false" columns="1">
        <apex:inputField value="{!candidate.First_Name__c}"  label="First Name"  />
        <apex:inputField value="{!candidate.Last_Name__c}"  label="Last Name" />
        <apex:inputField value="{!candidate.Email__c}"  label="Email"  />
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 

public with sharing class ApplicationCreateController {
 
  // the candidate record you are adding values to
  public Candidate__c candidate {
    get {
      if (candidate == null) candidate = new Candidate__c();
      return candidate;
    }
    set;
  }

  // the job application record you are adding values to
  public Job_Application__c jobapplication{
    get {
      if (jobapplication == null) jobapplication = new Job_Application__c();
      return jobapplication;
    }
    set;
  }
 
  public ApplicationCreateController() {
    // blank constructor
  }
 
  // save button is clicked
  public PageReference save() {
    try {
            insert candidate; // inserts the new record into the database
            insert jobapplication; // inserts the new record into the database            
            jobapplication.Candidate__c = candidate.Name; // THIS DOESNT SEEM TO SET THE CANDIDATE LOOKUP FIELD IN THE JOB APPLICATION   
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new candidate.'));
      return null;
    }
    // if successfully inserted new candidate, then displays the thank you page.
    return Page.Application_Create_Thankyou;
  }
}

 

The visualforce runs without error and I get a new candidate and job application object but the lookup reference between them is not set.

 

Any help would be very much appreciated?

 

Thanks

Bovis

  • October 22, 2012
  • Like
  • 0
I am on the last step of the Trailhead Account Geolocation project and I get the following error:
User-added image

Here is the code from the AccountMapController-- What did I do wrong?
({
      jsLoaded: function(component, event, helper) {

         setTimeout(function() {
            var map = L.map('map', {zoomControl: false})
                        .setView([37.784173, -122.401557], 14);
            L.tileLayer(
         'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
              {
                 attribution: 'Tiles © Esri'
              }).addTo(map);
            component.set("v.map", map);
         });
      },

      accountsLoaded: function(component, event, helper) {

         // Add markers
         var map = component.get('v.map');
         var accounts = event.getParam('accounts');
         for (var i=0; i<accounts.length; i++) {
              var account = accounts[i];
              var latLng = [account.Location__Latitude__s, account.Location__Longitude__s];
              L.marker(latLng, {account: account}).addTo(map).on('click', function(event) {
   helper.navigateToDetailsView(event.target.options.account.Id);
});

      accountSelected: function(component, event, helper) {
         // Center the map on the account selected in the list
         var map = component.get('v.map');
         var account = event.getParam("account");
         map.panTo([account.Location__Latitude__s, account.Location__Longitude__s]);
      }
})

Hi,

 

How do you create 2 custom objects using Visualforce and then associate one as a lookup field in the other? E.g. Lets use the recruiter application. I want someone to create themselves as a candidate and then apply for a job at the same time.

 

Here's the apex

<apex:page controller="ApplicationCreateController">
  <apex:sectionHeader title="Visualforce Example" subtitle="Create a Job Application"/>
  <apex:form >
    <apex:pageMessages /> <!-- this is where the error messages will appear -->
    <apex:pageBlock title="Candidate Info">
      <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection showHeader="false" columns="1">
        <apex:inputField value="{!candidate.First_Name__c}"  label="First Name"  />
        <apex:inputField value="{!candidate.Last_Name__c}"  label="Last Name" />
        <apex:inputField value="{!candidate.Email__c}"  label="Email"  />
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 

public with sharing class ApplicationCreateController {
 
  // the candidate record you are adding values to
  public Candidate__c candidate {
    get {
      if (candidate == null) candidate = new Candidate__c();
      return candidate;
    }
    set;
  }

  // the job application record you are adding values to
  public Job_Application__c jobapplication{
    get {
      if (jobapplication == null) jobapplication = new Job_Application__c();
      return jobapplication;
    }
    set;
  }
 
  public ApplicationCreateController() {
    // blank constructor
  }
 
  // save button is clicked
  public PageReference save() {
    try {
            insert candidate; // inserts the new record into the database
            insert jobapplication; // inserts the new record into the database            
            jobapplication.Candidate__c = candidate.Name; // THIS DOESNT SEEM TO SET THE CANDIDATE LOOKUP FIELD IN THE JOB APPLICATION   
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new candidate.'));
      return null;
    }
    // if successfully inserted new candidate, then displays the thank you page.
    return Page.Application_Create_Thankyou;
  }
}

 

The visualforce runs without error and I get a new candidate and job application object but the lookup reference between them is not set.

 

Any help would be very much appreciated?

 

Thanks

Bovis

  • October 22, 2012
  • Like
  • 0