• Cato1984
  • NEWBIE
  • 10 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hey All,

I believe my question will underline my lack of experience with Javascript more than anything else, but I am hoping this is the right place to ask this question anyway. I have a pageBlockTable that is iterating over a list of wrapper classes. Each wrapper class holds two select lists. The idea is to have one control the other. I uderstand how to use action functions to create a dependant picklist when all the requesite functionality resides in the controller itself. I seem to be missing something important when using action functions and specific individual iterations of a list. Can anyone help?

Short question - In the example page, controller and wrapper class below; how can I get the first select list for each iteration in the data table to control the second? The dependant select list outside the data table works as an example of what I am looking for.


<apex:page controller="TestController">

<apex:form id="pgFrm">
  <apex:actionFunction name="refreshDependent" action="{!buildSecondSelectList}" rerender="secList" />
  <apex:pageBlock title="Rerender Dependent Picklists" id="firstlBlk" >
   <apex:selectList value="{!val1}" size="1" onchange="refreshDependent()" id="firstList">
    <apex:selectOptions value="{!list1}"/>
   </apex:selectList>
   <apex:selectList value="{!val2}" size="1" id="secList">
    <apex:selectOptions value="{!list2}"/>
   </apex:selectList>
  </apex:pageBlock>
  <apex:pageBlock title="Test Wrapper Picklists" id="seclBlk" >
   <apex:pageBlockTable value="{!wrapperList}" var="wrapper" id="wrapperTable" >
    <apex:column headerValue="First Wrapper Select List" >
     <apex:selectList value="{!wrapper.wrapperVal1}" size="1" id="wrapFirList">
      <apex:selectOptions value="{!wrapper.wrapperList1}"/>
     </apex:selectList>
    </apex:column>
    <apex:column headerValue="Second Wrapper Select List" >
     <apex:selectList value="{!wrapper.wrapperVal2}" size="1" id="wrapSecList">
      <apex:selectOptions value="{!wrapper.wrapperList2}"/>
     </apex:selectList>
    </apex:column>
   </apex:pageBlockTable>
  </apex:pageBlock>
</apex:form>
</apex:page>


public with sharing class TestController {

public String val1 {get;set;}
public String val2 {get;set;}

public List<SelectOption> list1 {get;set;}
public List<SelectOption> list2 {get;set;}

public List<TestWrapper> wrapperList {get;set;}

public TestController() {
  wrapperList = new List<TestWrapper>();
  for (Integer i = 0; i < 3; i++) {
   wrapperList.add( new TestWrapper() );
  }
  buildFirstSelectList();
  buildSecondSelectList();
}

public void buildFirstSelectList() {
  list1 = new List<SelectOption>();
 
  list1.add( new SelectOption('Val1','Val1') );
  list1.add( new SelectOption('Val2','Val2') );
  list1.add( new SelectOption('Val3','Val3') );
}

public void buildSecondSelectList() {
  list2 = new List<SelectOption>();
  if (val1!=null&&val1=='Val1') {
   list2.add( new SelectOption('SecondVal1','SecondVal1') );
   list2.add( new SelectOption('SecondVal2','SecondVal2') );
   list2.add( new SelectOption('SecondVal3','SecondVal3') );
   list2.add( new SelectOption('SecondVal4','SecondVal4') );
  } else if (val1!=null&&val1=='Val2') {
   list2.add( new SelectOption('SecondVal5','SecondVal5') );
   list2.add( new SelectOption('SecondVal6','SecondVal6') );
   list2.add( new SelectOption('SecondVal7','SecondVal7') );
   list2.add( new SelectOption('SecondVal8','SecondVal8') );
  } else if (val1!=null&&val1=='Val3') {
   list2.add( new SelectOption('SecondVal9','SecondVal9') );
   list2.add( new SelectOption('SecondVal10','SecondVal10') );
   list2.add( new SelectOption('SecondVal11','SecondVal11') );
   list2.add( new SelectOption('SecondVal12','SecondVal12') );
  } else {
   list2.add( new SelectOption('SecondVal1','SecondVal1') );
   list2.add( new SelectOption('SecondVal2','SecondVal2') );
   list2.add( new SelectOption('SecondVal3','SecondVal3') );
   list2.add( new SelectOption('SecondVal4','SecondVal4') );
   list2.add( new SelectOption('SecondVal5','SecondVal5') );
   list2.add( new SelectOption('SecondVal6','SecondVal6') );
   list2.add( new SelectOption('SecondVal7','SecondVal7') );
   list2.add( new SelectOption('SecondVal8','SecondVal8') );
   list2.add( new SelectOption('SecondVal9','SecondVal9') );
   list2.add( new SelectOption('SecondVal10','SecondVal10') );
   list2.add( new SelectOption('SecondVal11','SecondVal11') );
   list2.add( new SelectOption('SecondVal12','SecondVal12') );
  }
}
}




public with sharing class TestWrapper {

public String wrapperVal1 {get;set;}
public String wrapperVal2 {get;set;}

public List<SelectOption> wrapperList1 {get;set;}
public List<SelectOption> wrapperList2 {get;set;}

public TestWrapper() {
  buildFirstSelectList();
  buildSecondSelectList();
}

public void buildFirstSelectList() {
  wrapperList1 = new List<SelectOption>();
 
  wrapperList1.add( new SelectOption('Wrapper Val1','Wrapper Val1') );
  wrapperList1.add( new SelectOption('Wrapper Val2','Wrapper Val2') );
  wrapperList1.add( new SelectOption('Wrapper Val3','Wrapper Val3') );
}

public void buildSecondSelectList() {
  wrapperList2 = new List<SelectOption>();
  if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val1') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal1','Wrapper SecondVal1') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal2','Wrapper SecondVal2') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal3','Wrapper SecondVal3') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal4','Wrapper SecondVal4') );
  } else if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val2') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal5','Wrapper SecondVal5') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal6','Wrapper SecondVal6') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal7','Wrapper SecondVal7') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal8','Wrapper SecondVal8') );
  } else if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val3') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal9','Wrapper SecondVal9') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal10','Wrapper SecondVal10') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal11','Wrapper SecondVal11') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal12','Wrapper SecondVal12') );
  } else {
   wrapperList2.add( new SelectOption('Wrapper SecondVal1','Wrapper SecondVal1') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal2','Wrapper SecondVal2') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal3','Wrapper SecondVal3') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal4','Wrapper SecondVal4') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal5','Wrapper SecondVal5') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal6','Wrapper SecondVal6') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal7','Wrapper SecondVal7') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal8','Wrapper SecondVal8') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal9','Wrapper SecondVal9') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal10','Wrapper SecondVal10') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal11','Wrapper SecondVal11') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal12','Wrapper SecondVal12') );
  }
}
}

This is a general question, I have no code examples yet. I hope I can convey my question in a manner you guys can understand without examples, let me know if I need to clarify.

 

I'm reading up on Apex, learning what I can do while I think through my solution. I will have two custom objects, one parent one child, so a one-to-many relationship. The child will have multiple Record Types. Several of the record types will have no limit on the number of recrds that can be created for each parent. There is however one record type where I will need to prevent the creation of that type if one already exists for that specific parent. I believe I can solve the issue with a before trigger. Where I get stumped is when these records get created in bulk, e.x. creating two hundred records via the data loader. I see the Database.insert() method will allow me to do partial saves on after triggers, but there is no documentation around before triggers and partial saves, at least none that I can find. Do before triggers support partial saves natively? If not, is there some other way I can ensure partial data loads?

 

Thanks in advance,

Cato

Hey All,

I believe my question will underline my lack of experience with Javascript more than anything else, but I am hoping this is the right place to ask this question anyway. I have a pageBlockTable that is iterating over a list of wrapper classes. Each wrapper class holds two select lists. The idea is to have one control the other. I uderstand how to use action functions to create a dependant picklist when all the requesite functionality resides in the controller itself. I seem to be missing something important when using action functions and specific individual iterations of a list. Can anyone help?

Short question - In the example page, controller and wrapper class below; how can I get the first select list for each iteration in the data table to control the second? The dependant select list outside the data table works as an example of what I am looking for.


<apex:page controller="TestController">

<apex:form id="pgFrm">
  <apex:actionFunction name="refreshDependent" action="{!buildSecondSelectList}" rerender="secList" />
  <apex:pageBlock title="Rerender Dependent Picklists" id="firstlBlk" >
   <apex:selectList value="{!val1}" size="1" onchange="refreshDependent()" id="firstList">
    <apex:selectOptions value="{!list1}"/>
   </apex:selectList>
   <apex:selectList value="{!val2}" size="1" id="secList">
    <apex:selectOptions value="{!list2}"/>
   </apex:selectList>
  </apex:pageBlock>
  <apex:pageBlock title="Test Wrapper Picklists" id="seclBlk" >
   <apex:pageBlockTable value="{!wrapperList}" var="wrapper" id="wrapperTable" >
    <apex:column headerValue="First Wrapper Select List" >
     <apex:selectList value="{!wrapper.wrapperVal1}" size="1" id="wrapFirList">
      <apex:selectOptions value="{!wrapper.wrapperList1}"/>
     </apex:selectList>
    </apex:column>
    <apex:column headerValue="Second Wrapper Select List" >
     <apex:selectList value="{!wrapper.wrapperVal2}" size="1" id="wrapSecList">
      <apex:selectOptions value="{!wrapper.wrapperList2}"/>
     </apex:selectList>
    </apex:column>
   </apex:pageBlockTable>
  </apex:pageBlock>
</apex:form>
</apex:page>


public with sharing class TestController {

public String val1 {get;set;}
public String val2 {get;set;}

public List<SelectOption> list1 {get;set;}
public List<SelectOption> list2 {get;set;}

public List<TestWrapper> wrapperList {get;set;}

public TestController() {
  wrapperList = new List<TestWrapper>();
  for (Integer i = 0; i < 3; i++) {
   wrapperList.add( new TestWrapper() );
  }
  buildFirstSelectList();
  buildSecondSelectList();
}

public void buildFirstSelectList() {
  list1 = new List<SelectOption>();
 
  list1.add( new SelectOption('Val1','Val1') );
  list1.add( new SelectOption('Val2','Val2') );
  list1.add( new SelectOption('Val3','Val3') );
}

public void buildSecondSelectList() {
  list2 = new List<SelectOption>();
  if (val1!=null&&val1=='Val1') {
   list2.add( new SelectOption('SecondVal1','SecondVal1') );
   list2.add( new SelectOption('SecondVal2','SecondVal2') );
   list2.add( new SelectOption('SecondVal3','SecondVal3') );
   list2.add( new SelectOption('SecondVal4','SecondVal4') );
  } else if (val1!=null&&val1=='Val2') {
   list2.add( new SelectOption('SecondVal5','SecondVal5') );
   list2.add( new SelectOption('SecondVal6','SecondVal6') );
   list2.add( new SelectOption('SecondVal7','SecondVal7') );
   list2.add( new SelectOption('SecondVal8','SecondVal8') );
  } else if (val1!=null&&val1=='Val3') {
   list2.add( new SelectOption('SecondVal9','SecondVal9') );
   list2.add( new SelectOption('SecondVal10','SecondVal10') );
   list2.add( new SelectOption('SecondVal11','SecondVal11') );
   list2.add( new SelectOption('SecondVal12','SecondVal12') );
  } else {
   list2.add( new SelectOption('SecondVal1','SecondVal1') );
   list2.add( new SelectOption('SecondVal2','SecondVal2') );
   list2.add( new SelectOption('SecondVal3','SecondVal3') );
   list2.add( new SelectOption('SecondVal4','SecondVal4') );
   list2.add( new SelectOption('SecondVal5','SecondVal5') );
   list2.add( new SelectOption('SecondVal6','SecondVal6') );
   list2.add( new SelectOption('SecondVal7','SecondVal7') );
   list2.add( new SelectOption('SecondVal8','SecondVal8') );
   list2.add( new SelectOption('SecondVal9','SecondVal9') );
   list2.add( new SelectOption('SecondVal10','SecondVal10') );
   list2.add( new SelectOption('SecondVal11','SecondVal11') );
   list2.add( new SelectOption('SecondVal12','SecondVal12') );
  }
}
}




public with sharing class TestWrapper {

public String wrapperVal1 {get;set;}
public String wrapperVal2 {get;set;}

public List<SelectOption> wrapperList1 {get;set;}
public List<SelectOption> wrapperList2 {get;set;}

public TestWrapper() {
  buildFirstSelectList();
  buildSecondSelectList();
}

public void buildFirstSelectList() {
  wrapperList1 = new List<SelectOption>();
 
  wrapperList1.add( new SelectOption('Wrapper Val1','Wrapper Val1') );
  wrapperList1.add( new SelectOption('Wrapper Val2','Wrapper Val2') );
  wrapperList1.add( new SelectOption('Wrapper Val3','Wrapper Val3') );
}

public void buildSecondSelectList() {
  wrapperList2 = new List<SelectOption>();
  if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val1') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal1','Wrapper SecondVal1') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal2','Wrapper SecondVal2') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal3','Wrapper SecondVal3') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal4','Wrapper SecondVal4') );
  } else if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val2') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal5','Wrapper SecondVal5') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal6','Wrapper SecondVal6') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal7','Wrapper SecondVal7') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal8','Wrapper SecondVal8') );
  } else if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val3') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal9','Wrapper SecondVal9') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal10','Wrapper SecondVal10') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal11','Wrapper SecondVal11') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal12','Wrapper SecondVal12') );
  } else {
   wrapperList2.add( new SelectOption('Wrapper SecondVal1','Wrapper SecondVal1') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal2','Wrapper SecondVal2') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal3','Wrapper SecondVal3') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal4','Wrapper SecondVal4') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal5','Wrapper SecondVal5') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal6','Wrapper SecondVal6') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal7','Wrapper SecondVal7') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal8','Wrapper SecondVal8') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal9','Wrapper SecondVal9') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal10','Wrapper SecondVal10') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal11','Wrapper SecondVal11') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal12','Wrapper SecondVal12') );
  }
}
}

Hi,

 

I am a newbie when it comes to apex and could do with some guidance. Basically, I am trying to create two different triggers, each firing under different scenarios.

 

On the first instance, I'd like a trigger which would fire when a checkbox is populated in an account and create a child record (populating the lookup and some fields on the child object) and on another instance, I'd like it to trigger when a certain value is selected from a picklist, creating a child record of the account and populating fields in both the account & child object.

 

Any ideas would be amazing!

 

Thanks.

  • March 17, 2013
  • Like
  • 0