function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kevindotcarkevindotcar 

Urgent Problem with SelectLists in a controller extension

 

Hi all,

 

I have a page that has an extension class, and whenever I try to update a variable in the extension from a SelectList, it just doesn't happen.

 

Page snippet:

<apex:page standardController="Opportunity" extensions="SelfEnrollController" action="{!getParameters}" id="SelfEnrollPage">

<apex:form id="SelfEnrollForm">
...
<b>Primary Category:</b> 
<apex:SelectList id="Positions" value="{!strPrimryCatId}"  size="1" multiselect="false">
<apex:selectOptions value="{!CategoryItems}"/>
</apex:SelectList> <br/>

...

 

 

Controller snippet:

 

public  class SelfEnrollController {
Public String strPrimryCatId{get;set;}
public void getParameters() {
...
Public List<SelectOption> getCategoryItems() {
 List<SelectOption> options = new List<SelectOption>();

   for(jsonPrimaryCategories  c :cloneCategory) {
     System.debug('c.Id: ' + c.Id + ', c.Value: ' + c.Value);
     options.add(new SelectOption (c.Id,c.Value));
     }
   return options;
   }    
}



Do I have to do anything different becayse the selectlist is updating a value in an extension?

 

Help?

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
kevindotcarkevindotcar

Hi Khaiwong

 

Just to follow-up.... I got my problem fixed, but it still seems strange.

 

I build my selection list much like I stated in my original post:

 

 <apex:SelectList value="{!strMOPId}" size="1" onChange="callUpdate()" multiselect="false">
    <apex:selectOptions value="{!theXMOPItems}"/>
 </apex:SelectList> <br/>
 

 

But I added the "onChange" javascript, which is as follows;

 

<script>
 function callUpdate(){
     updateCategory('abc');
     }     
</script>

...

<apex:actionFunction name="updateCategory" action="{!updateMOP}" rerender="zzz"/>

 

,...Where the "{!updateMOP}" doesn't do much at all, and there is no "zzz" ID to rerender -

For the life of me, I don't know what's going on....

 

I was just hoping that posting the solution might help explain what the problem I'm having is...

 

 

 

All Answers

Hengky IlawanHengky Ilawan

Hi,

 

Looks OK to me.

What's in your getParameters() method?

 

-Hengky-

sf_evolutionsf_evolution

Hi Khaiwong,

 

Really, just a bunch of initialization stuff I pull out of the opportunity id that's pased to the page:

 

 

  public void getParameters() {        
         internalTest = false;    //DEBUG
         
         Opportunity_id  = ApexPages.currentPage().getParameters().get('Id');
         System.debug('Opportunity_id: ' + Opportunity_id  );
         strListingId= ApexPages.currentPage().getParameters().get('ListingId');
         strCID = ApexPages.currentPage().getParameters().get('customerId');
         strPrimryCatDesc = ApexPages.currentPage().getParameters().get('PrimaryCatDesc');                 
         
         strImageURL = 'HTTPS://' + ApexPages.currentPage().getHeaders().get('Host');
         strImageURL = strImageURL.replace('visual', 'content');   // problem with VF vs. Live
         
         strImageURL  += '/servlet/servlet.FileDownload?file=';
         strAdImageURL = strImageURL;   // Ad Image
         strProfileImageURL = strImageURL;   // ... Image

         theNetworkSuppression = 'Y';
         theAddressSuppression = 'Y';
         theMeterType = '1';

         if(bIsTest)
             strJSON = '{"status":"SUCCESS","primaryTags":[{"id":3748,"value":"Real Estate Sales & Services"},{"id":3849,"value":"Shopping"},{"id":4334,"value":"Wholesalers"}],"messages":[]}';
         else
             strJSON = EncodingUtil.urlDecode(ApexPages.currentPage().getParameters().get('JSON'), 'UTF-8');
         
         System.debug('JSON PASSED: ' + strJSON);
         System.debug('Opportunity ID: ' + Opportunity_id);

         // TODO: -- FIRST:  Get All the required Opportunity Info
         // Problems:   Pricebook entries???
         //             Campaign ID???
         //             Contract Notes???

         rs_oppy = [Select ...
                     Sponsored_Ad1__c, Sponsored_Ad2__c

                  FROM Opportunity
                  WHERE Id = :Opportunity_id
                  LIMIT 1];


             theAOpportunity = rs_oppy[0];

             strRepId = theAOpportunity.Owner.Account_Rep_ID__c;
             strRepName = theAOpportunity.Account.Owner.FirstName + ' ' + theAOpportunity.Account.Owner.LastName;

             Id AttParent = theAOpportunity.Id;
             // NOW GET Logo ATTACHMENT if any....
             System.debug('Attachment Parent: ' + AttParent);

             att = [SELECT Id ...
                 AND Description = 'Logo'
                 LIMIT 1];

             adAtt = [SELECT Id,...
                 WHERE ParentId = :Opportunity_id
                 AND Description = 'Advertisement'
                 LIMIT 1];

             profileAtt = [SELECT Id, ...
                 WHERE ParentId = :Opportunity_id
                 AND Description = 'Profile'
                 LIMIT 1];

         // NOW GET JSON INFO
         ListingId theListing = (ListingId ) JSON.deserialize(strJSON, ListingId.class);
         if(theListing != null) {
             if(theListing.activeBillingAccounts != null) {
                 for(jsonAccounts  b :theListing.activeBillingAccounts) {
                     jsonAccounts xListing = new jsonAccounts();

                     xListing.id = b.id;
                     xListing.value = b.value;
                     cloneListing.add(xListing);
                     }
             
          }
         else {   // look for it on the BillingAccts param
              //{"jsonAccounts":[{"value":"Visa-181","id":"7252"}]}
              String strPmt_ids  = ApexPages.currentPage().getParameters().get('BillingAccts');
              strPmt_ids = '{"activeBillingAccounts": ' + strPmt_ids + '}';
                  accountList yyListing = new accountList();
                
                  yyListing = (accountList) JSON.deserialize(strPmt_ids, accountList.class);            
                  
                  if(yyListing != null) {
                   //System.debug('yyListing SIZE: ' + yyListing.activeBillingAccounts.size());
                   for(jsonAccounts  b :yyListing.activeBillingAccounts) {
                     jsonAccounts xListing = new jsonAccounts();
                     
                     xListing.id = b.id;
                     xListing.value = b.value;
                     cloneListing.add(xListing);
                     }
                   }
                  theMOPAccount =  yyListing.activeBillingAccounts[0];  
                  ///strMOPId = theMOPAccount.Id;
                  
                  theListing.activeBillingAccounts =  yyListing.activeBillingAccounts;  
                  
             }
             
         for(jsonPrimaryCategories  c1 :theListing.primaryTags) {
                jsonPrimaryCategories xCategory = new jsonPrimaryCategories();
                xCategory.id = c1.id;
                xCategory.value = c1.value;
                cloneCategory.add(xCategory);
                }
             }

             
         strPrPromoId = theAOpportunity.Enroll_Promo_Code__c;
         Account_id = theAOpportunity.Account.Id;

   
         rs_acct = [Select Id, Name,  Customer_Id__c, Owner.FirstName, Owner.lastname, Owner.Account_Rep_ID__c
                  FROM Account
                  WHERE Id = :Account_id
                  LIMIT 1];

         // SET DEFAULT VALUES
         theMOPAccount = theListing.activeBillingAccounts[0];
         //strMOPId = theMOPAccount.Id;
         
         //theCategory = theListing.primaryTags[0].Id;
         //strCID = theAOpportunity.Account.Customer_Id__c;
         theBillingDay = '1';
         theBillingMonths = '1';
         theTiers = '1';
         theAllocation = '1';
         theDiscoutType = '1';   // FIXED
         theDiscountValue = '0.0';
         System.debug('theAllocation : ' + theAllocation );
         Date lDt = theAOpportunity.Campaign_Start__c;
         if(lDt  == null)   {lDt = date.today();}
         strConvertedDate =  lDt.month().format() + '/0' + lDt.day().format() + '/' + lDt.year();
         System.debug('strConvertedDate: ' + strConvertedDate);
         }

 

Really nothing related... but it's necessary for the progtam to run..... but it doesn;t touch the "strPrimryCatId " variable....

 

 

kevindotcarkevindotcar

Hi Khaiwong

 

Just to follow-up.... I got my problem fixed, but it still seems strange.

 

I build my selection list much like I stated in my original post:

 

 <apex:SelectList value="{!strMOPId}" size="1" onChange="callUpdate()" multiselect="false">
    <apex:selectOptions value="{!theXMOPItems}"/>
 </apex:SelectList> <br/>
 

 

But I added the "onChange" javascript, which is as follows;

 

<script>
 function callUpdate(){
     updateCategory('abc');
     }     
</script>

...

<apex:actionFunction name="updateCategory" action="{!updateMOP}" rerender="zzz"/>

 

,...Where the "{!updateMOP}" doesn't do much at all, and there is no "zzz" ID to rerender -

For the life of me, I don't know what's going on....

 

I was just hoping that posting the solution might help explain what the problem I'm having is...

 

 

 

This was selected as the best answer