0

All, I have a controller that updates a visualforce page. An interaction gets created first just fine but when I try to update it the page reloads and there is no record update. I looked at the debug log and there is nothing being recorded for system.debug. Please note that inteId has a value and I even hardcoded an id for testing and nothing. I did the same for type__c just in case. I have searched the web for days and decided to seek your assistance. Can you please help?

public Id inteId {get;set;} 
public String selectedPrg {get;set;}    
public String selectedType {get;set;}
public String selectedDirection {get;set;}
public String selectedSubject {get;set;}   

public PageReference save() {    

   List<Interaction__c>  inteLst = new List<Interaction__c>();
   List<Interaction__c> iLst = [select Id, Program__c, Type__c, Direction__c, Subject__c from Interaction__c where Id =: inteId limit 1];        

   System.debug('The inteId: ' + inteId);
   System.debug('the selected interaction data: '+selectedPrg+'_'+selectedDirection); 

   for(Interaction__c i : iLst){                                  
     if(iLst.size()> 0){            
        i.Program__c = selectedPrg;  
        i.Type__c = 'Call'; //selectedType;
        i.Direction__c = selectedDirection;
        i.Subject__c = selectedSubject;
        inteLst.add(i);                      
     }
   }            

   try {
     update inteLst;
   }catch(Exception ex){    
      system.debug('Exception is' + ex);
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Exception is'));
   }  
  return null;                                 
} 

Example VF

  <div class="row">
      <label class="control-label col-sm-2" for="intesubject">Subject:</label>
      <div class="col-sm-4">
        <apex:selectList id="intesubject" size="1" value="{!selectedSubject}" required="false" styleClass="form-control"> <!-- required="true" prevents the find acct from working -->   
        <apex:selectOptions value="{!Subject}"/>
        </apex:selectList>              
       <span class="help-block">
            Please select an interaction subject.
       </span>

       <br/>
           <apex:commandButton id="updateint" styleClass="btn btn-primary" action="{!save}" onclick="" value="Update" /> 
       <span class="help-block">
            Click to update the interaction.
       </span>

      </div>
  </div

The last thing that appears in the debug log is the "subject" picklist. There is nothing concerning the "save" action after it.

enter image description here

1

I found the issue after rebuilding the VF page little by little. It turns out that I had two tags for the form class="form-horizontal". Perhaps adding ids would have solved the problem but removing one of them the trick and everything is working. I appreciate all the help!!

<apex:form>

<form class="form-horizontal" role="form" action="#">
  <!-- page 1 of SPA -->
</form>

<form class="form-horizontal" role="form" action="#">
  <!-- page 2 of SPA-->
</form>

</apex:form> 
0

I have made an update to your VF Controller, I cut out the reassignment of the list to a new list. See if this makes any difference:

public Id inteId {get;set;} 
public String selectedPrg {get;set;}    
public String selectedType {get;set;}
public String selectedDirection {get;set;}
public String selectedSubject {get;set;}   

public PageReference save() {    

    //This is not needed
   //List<Interaction__c>  inteLst = new List<Interaction__c>();
   List<Interaction__c> iLst = [select Id, Program__c, Type__c, Direction__c, Subject__c from Interaction__c where Id =: inteId limit 1];        

   System.debug('The inteId: ' + inteId);
   System.debug('the selected interaction data: '+selectedPrg+'_'+selectedDirection); 

   for(Interaction__c i : iLst){                                  
     if(iLst.size()> 0){            
        i.Program__c = selectedPrg;  
        i.Type__c = 'Call'; //selectedType;
        i.Direction__c = selectedDirection;
        i.Subject__c = selectedSubject;
        //inteLst.add(i); This is not needed
     }
   }            

   try {
     update iLst;
   }catch(Exception ex){    
      system.debug('Exception is' + ex);
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Exception is'));
   }  
  return null;                                 
} 

From what it seems like your Debug log is telling us, it seems as though your save() method is never being called. I would want to make sure your <apex:page> controller parameter is being set correctly.

10
  • Hi Bryan, thanks so much for looking into this. I tried that without results. When I click the button the page reloads and the form resets, perhaps this has something to do with it. I am not getting any errors either and the "save" PageReference is not being tracked in the debug log at all, none of it. Thoughts? Thanks!
    – Snights
    Nov 20 '19 at 19:01
  • Can you remove the try catch temporarily and just perform the update and see if any errors are happening at all Nov 20 '19 at 19:04
  • Done, no errors to troubleshoot : (
    – Snights
    Nov 20 '19 at 19:31
  • 1
    Hmm, can you include the <apex:page> tag in your VF code? Also can you remove the onclick attribute from your commandButton Nov 20 '19 at 19:57
  • 1
    Adding more explanation in the body of your answer would probably help OP better understand what the issue is. Right now, this answer is pretty close to being a code dump.
    – Derek F
    Nov 20 '19 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.