• Richard Houston 20
  • NEWBIE
  • 40 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 8
    Replies
So I have this scenario working fine using HTML/Apex, but need to make it mobile friendly using javascript remoting.

There is a survey page with ~30 questions that are yes/no and write a number value. The requirement is that we ure radio buttons.

I've got the remote action to pull the value from the existing record and display it an <input type="number"> field.

However, how do I take that value, check to see if the number equals the value of the radio selector, then check the appropriate selector?

Ex: 
 
Do you like apples?

<input onchange="radioCheck()" id="ViaCBY" type="radio" name="ViaCB" value="8" ></input><label> Yes (8)</label>

​<input onchange="radioCheck()" id="ViaCBY" type="radio" name="ViaCB" value="0" ></input><label>No (0)</label>
If the stored value in the record is loaded with an 8, how do I load the page with 8 selected? And the inverse true as well?


Here's my current code:
Remote action in controller:
 
@RemoteAction
    global static Boolean setSurvey(
        String whId, String comments, Integer CompDistance, Integer ViaCB, Integer ViaBond) {

        // Get the warehouse record for the Id
        Pursuit_Survey__c PS = EvaluationEditor.getSurvey(whId);

        // Update fields
        // Note that we're not validating / sanitizing, for simplicity
        PS.Pursuit_Survey_Comments__c = comments.trim();
        PS.COMP_Distance__c = CompDistance;
        PS.Viability_Clark_Budget__c = ViaCB;
        PS.Viability_Bonding__c = ViaBond;

        // Save the updated record
        // This should be wrapped in an exception handler
        update PS;

        return true;
    }
}


Visualforce page script:
 
$(document).ready(function(){
        // Load the record
        loadWarehouse();
    });

    // Utility; parse out parameter by name from URL query string
    $.urlParam = function(name){
        var results = new RegExp('[\\?&]' + name + '=([^&#]*)')
            .exec(window.location.href);
        return results[1] || 0;
    }

    function loadWarehouse() {
        // Get the record Id from the GET query string
        SurveyId = $.urlParam('id');

        // Call the remote action to retrieve the record data
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.EvaluationEditor.getSurvey}',
            SurveyId,
            function(result, event){;
                if(event.status){
                    console.log("Your id value is " + SurveyId);
                    $('#comments').val(result.Pursuit_Survey_Comments__c);
                    $('#Survey_name').text(result.Name);
                    $('#Opportunity_name').text(result.Opportunity__r.Name);
                    $('#CompDistance').val(result.COMP_Distance__c);
                    $('#ViaCB').val(result.Viability_Clark_Budget__c);
                    $('#ViaBond').val(result.Viability_Bonding__c);
                    console.log("Your survey comments are: "+result.Pursuit_Survey_Comments__c);
                    
                } else if (event.type === 'exception'){
                    console.log(result);
                } else {
                    // unexpected problem...
                }
        });
    }
    
//    function defaluts(){
//        var x = 8;
//        $('input[name=ViaCB][value=' + x + ']').prop('checked',true);
//    }

Input fields:
 
<h4>Question</h4>
                <div class="form-control form-control-radio form-control-radio-thumbs span-50">
                    <input onchange="radioCheck()" id="ViaCBY" type="radio" name="ViaCB" value="8" ></input><label> Yes (8)</label>
                </div>
                <div class="form-control form-control-radio form-control-radio-thumbs span-50">
                    <input onchange="radioCheck()" id="ViaCBN" type="radio" name="ViaCB" value="0"></input><label > No (0)</label>
                </div>
                <div class="form-control form-control-radio form-control-radio-thumbs span-50">
                    <input onchange="radioCheck()" id="ViaCBY" type="radio" name="ViaCBC" value="2"></input><label> Yes (2)</label>
                </div>
                <div class="form-control form-control-radio form-control-radio-thumbs span-50">
                    <input onchange="radioCheck()" id="ViaCBN" type="radio" name="ViaCBC" value="0"></input><label > No (0)</label>
                </div>
            </div><!--.form-control-group-->


 
I'm having an issue with what appears to be an order of opperations issue with a visualforce page, custom save method, validation rules, and an onclick confirmation dialogue. Before adding the onclick piece, the page would try the save, and if it encountered a validation rule, would not update any fields in the current record.

However, with the onclick message, it now does write values to the current record. Problematically it writes to the "Submitted__c" field as true. This then changes the VF page to disable any editing. But if it encounters a validation rule, the user still needs to be able to edit. 

So the question is, why does the save method behave differently when the onclick dialogue box is added? 

Validation rule: each field requires a response (didn't want to use required fields due to issues with rerender attributes)
Or(ISBLANK(Field1),
ISBLANK(Field2),
ISBLANK(Field3),
ISBLANK(Field4))

Save method:
public PageReference saveandSubmit(){
         Try{             
           PursuitChild.Submitted__c = true;
           PursuitChild.Submitted_User__c= UserInfo.GetUserID();
           PursuitChild.Date_Submitted__c =  date.today();
                Upsert PursuitChild;
           ParentOpp.Submit_for_Approval__c = true;
           ParentOpp.Priority_Survey__c = PursuitChild.Proposed_Priority__c;
           update ParentOpp;       
           System.debug(PursuitChild);
           PageReference ref = new PageReference('/' + PursuitChild.Opportunity__c);
           ref.setRedirect(true);
           return ref;
         }
         catch(DmlException e){
           System.debug('The following exception has occurred: ' + e.getMessage());
           Apexpages.Addmessages(e);
           } 
           return null;
    }

Button with onclick function:
 
<apex:commandButton value="Save and Submit" action="{!saveandSubmit}" onclick="if(!confirm('After submitting this record it cannot be edited again.')){return false;}" />

I do have <apex:pagemessages /> included in my page to display any errors.

Thanks for the help!


Everything was operating as expected prior to adding the onclick function asking the user to confirm the action. 

 
Hi,

I'm having trouble getting some of the parent record information to display on my visualforce page. I have a custom controller extension that is returning the values when I open the logs. However, the fields do not populate on the Visualforce page.

Parent Obejct - Opportunity
Child Object - Pursuit Survey

I'm trying to get StageName from opportunity to show on the custom visualforce page.

 
public with sharing class SurveyParentIDExt{
    public Pursuit_Survey__c PursuitChild{get;set;}
    public Opportunity ParentOpp{get;set;}
    
    public SurveyParentIDExt(ApexPages.StandardController controller){
        PursuitChild=(Pursuit_Survey__c)controller.getRecord();
        String oppid = (PursuitChild.Opportunity__c);
        String parentID = System.currentPagereference().getParameters().get('parentid');
        if (parentID != null){
            PursuitChild.Opportunity__c=parentid;  
        }     
        Opportunity ParentOpp = [SELECt name, id, stagename, priority__c from Opportunity where id =: parentid];
    system.debug(PursuitChild);
    system.debug(PursuitChild.Opportunity__c); 
    system.debug(ParentOpp);
    }

When I look for the debug of ParentOpp, it does return all of the fields and values as expected:
 
14:21:18:203 USER_DEBUG [15]|DEBUG|Opportunity:{Name=Pursuit Survey Process, Id=006e000000An8XJAAZ, StageName=Pursuing, Priority__c=Target, RecordTypeId=012i00000002n45AAA}

When I try and call the StageName in my visualforce page with: 
Opportunity Stage: <apex:outputfield value="{!ParentOpp.StageName}" />

Nothing is rendered. It remains a blank space (and I'll write your name....to all the Taylor fans).

Thanks so much for any help!

Richard 
Hi,

I'm having an issue getting a record's parent fields to display properly on a new visiualforce page. When I first create the visualforce page the parent ID (Opportunity.ID) is written into a lookup field on the child object record (Pursuit_Survey__c.Opportunity__c). This value returns and renders as expected when creating a new opportunity. 

However, when I try and reference any other related fields on the opportunity I get either blanks, or in the case of dates, the system date/time. 

Thanks for your help! 
Richard 

Controller extension
public with sharing class SurveyParentIDExt{
    public Pursuit_Survey__c PursuitChild{get;set;}
    public Opportunity ParentOpp{get;set;}
    
    public SurveyParentIDExt(ApexPages.StandardController controller){
        PursuitChild=(Pursuit_Survey__c)controller.getRecord();
        String oppid = (PursuitChild.Opportunity__c);
        String parentID = System.currentPagereference().getParameters().get('parentid');
        if (parentID != null){
        	PursuitChild.Opportunity__c=parentid;   
        	}     
    system.debug(PursuitChild.Opportunity__c); 
    }



VF Page snippet
 
<apex:page standardController="Pursuit_Survey__c" extensions="SurveyParentIDExt">

<apex:pageBlock >
                            <apex:pageMessages id="messages"></apex:pageMessages>
                            <h2>Opportunity: &nbsp; <apex:outputfield value="{!Pursuit_Survey__c.Opportunity__c}" /> 
                                <br/><br/>
                            	Award Date: &nbsp; <apex:OutputField value="{!Pursuit_Survey__c.Opportunity__r.CloseDate}"></apex:OutputField>
                                <br/><br/>
                                Contract Value: &nbsp;<apex:outputField value="{!Pursuit_Survey__c.Opportunity__r.Contract_Value__c}"/>
                                <br/><br/>
                                Description: &nbsp; <apex:outputField value="{!Pursuit_Survey__c.Opportunity__r.Description}"/>
                                <br/><br/>
</apex:pageblock>
</apex:page>


Opportunity name renders the lookup information. Howver the other fields are blank until after the record is saved. How do I get them to show before the record is saved?
Hi,

I have a custom visualforce page with a working save and insert button for a custom child object of opportunities. 

However, I'm running into an issue with the save and redirect when going back in to view/edit the record. I've overriden the custom object's view button to direct to a copy of the existing visualforce page. This one only has a button to update the record instead of inserting a new one. Looking at the debug logs the parent opportunity ID never seems to get passed through and then the page reference returns null. 

How do I go about getting that ID so I can return users to the page they came from?

Thanks!

Controller Extension: 
public with sharing class SurveyParentIDExt{
    public Pursuit_Survey__c OpportunityParent{get;set;}
    
    public SurveyParentIDExt(ApexPages.StandardController controller){
        OpportunityParent=(Pursuit_Survey__c)controller.getRecord();
        system.debug(OpportunityParent);
        String parentID = System.currentPagereference().getParameters().get('parentid');
        OpportunityParent.Opportunity__c=parentid;        
    system.debug(parentid);
    
    }
       public PageReference doSaveWithRedirect(){
        Upsert OpportunityParent;
           system.debug(opportunityparent);
        PageReference ref = new PageReference('/' + System.currentPagereference().getParameters().get('parentid'));
           system.debug(ref);
        ref.setRedirect(true);
        return ref;
    }
    public PageReference saveandUpdate(){
        Update OpportunityParent;
        system.debug(OpportunityParent);
        PageReference ref = new PageReference('/' + System.currentPagereference().getParameters().get('parentid'));
        system.debug(ref);
        ref.setRedirect(true);
        return ref;
       
    }
}

Visualforce Page
 
<apex:page standardController="Pursuit_Survey__c" extensions="SurveyParentIDExt">

<apex:form >
..
..
..
 [Skipping the body to keep this shorter]

  <apex:commandButton  value="Update Responses" action="{!saveandUpdate}" />
</apex:form>
</apex:page>

 
Hi,

I have a custom controller for a visualforce page that contains a flow. I'm not sure where to even start to write a test class for it. Any help would be most appreciated! 

What I have is a custom object, Project Information, that has a record created through the flow. The exit page is then set to the newly created record's page. ProjInfoID is a variable within the flow. 
public class ProjInfoFlowController {

    public Flow.Interview.CreateProjInfo myFlow { get; set; }
    
    public String getmyID() {
        if (myFlow==null) return '';
        else return myFlow.ProjInfoID;
        }
    
    public PageReference getOID(){
        PageReference p = new PageReference('/' + getmyID());
        p.setRedirect(true);
        return p;
        }

}

 
I'm getting my feet wet trying to write my first trigger and like many others am running into some errors. 

We have a custom object, Project Information, that is a child in a master-detial lookup to opportunities. I have a user lookup field on both opportunities and project information that I want to keep in sync with each other. Changes to the lookup only occur on the Opportunity record. 

I'm getting an error on the code below on line 4 (obj.REO_User_Record__c=Opportunity.REO__c;), "I'llegal assignemtn from Schema.SObjectField to Id. How do I get the UserID from the opportunity lookup into the Project Information lookup?

Thanks for the help!
 
trigger UpdateREO on Opportunity (after update,after insert) {
	List<Project_Information__c>IstToUpdate=new List<Project_Information__c>();
    for(Project_Information__c obj :[select id,name,REO_User_Record__c,Opportunity__c from Project_Information__c where Opportunity__c != null and Opportunity__c in : trigger.new]){
        obj.REO_User_Record__c=Opportunity.REO__c;
        IstToUpdate.add(obj);        
    }
    if(!IstToUpdate.isEmpty())
        update IstToUpdate;
    
}

 
Hi,

I'm trying to determine if it's possible to have a popup box/window with a picklist appear when an opportunity is saved if the stage equals won or lost. Within the window we also need to save another field to the opportunity record. 

We're trying to get users to input this data as it's fairly critical in evaluating our sales process. A validation rule was considered but due to internal company reasons will not be used.

Thanks in advance for any help! 
I'm having an issue with what appears to be an order of opperations issue with a visualforce page, custom save method, validation rules, and an onclick confirmation dialogue. Before adding the onclick piece, the page would try the save, and if it encountered a validation rule, would not update any fields in the current record.

However, with the onclick message, it now does write values to the current record. Problematically it writes to the "Submitted__c" field as true. This then changes the VF page to disable any editing. But if it encounters a validation rule, the user still needs to be able to edit. 

So the question is, why does the save method behave differently when the onclick dialogue box is added? 

Validation rule: each field requires a response (didn't want to use required fields due to issues with rerender attributes)
Or(ISBLANK(Field1),
ISBLANK(Field2),
ISBLANK(Field3),
ISBLANK(Field4))

Save method:
public PageReference saveandSubmit(){
         Try{             
           PursuitChild.Submitted__c = true;
           PursuitChild.Submitted_User__c= UserInfo.GetUserID();
           PursuitChild.Date_Submitted__c =  date.today();
                Upsert PursuitChild;
           ParentOpp.Submit_for_Approval__c = true;
           ParentOpp.Priority_Survey__c = PursuitChild.Proposed_Priority__c;
           update ParentOpp;       
           System.debug(PursuitChild);
           PageReference ref = new PageReference('/' + PursuitChild.Opportunity__c);
           ref.setRedirect(true);
           return ref;
         }
         catch(DmlException e){
           System.debug('The following exception has occurred: ' + e.getMessage());
           Apexpages.Addmessages(e);
           } 
           return null;
    }

Button with onclick function:
 
<apex:commandButton value="Save and Submit" action="{!saveandSubmit}" onclick="if(!confirm('After submitting this record it cannot be edited again.')){return false;}" />

I do have <apex:pagemessages /> included in my page to display any errors.

Thanks for the help!


Everything was operating as expected prior to adding the onclick function asking the user to confirm the action. 

 
Hi,

I'm having trouble getting some of the parent record information to display on my visualforce page. I have a custom controller extension that is returning the values when I open the logs. However, the fields do not populate on the Visualforce page.

Parent Obejct - Opportunity
Child Object - Pursuit Survey

I'm trying to get StageName from opportunity to show on the custom visualforce page.

 
public with sharing class SurveyParentIDExt{
    public Pursuit_Survey__c PursuitChild{get;set;}
    public Opportunity ParentOpp{get;set;}
    
    public SurveyParentIDExt(ApexPages.StandardController controller){
        PursuitChild=(Pursuit_Survey__c)controller.getRecord();
        String oppid = (PursuitChild.Opportunity__c);
        String parentID = System.currentPagereference().getParameters().get('parentid');
        if (parentID != null){
            PursuitChild.Opportunity__c=parentid;  
        }     
        Opportunity ParentOpp = [SELECt name, id, stagename, priority__c from Opportunity where id =: parentid];
    system.debug(PursuitChild);
    system.debug(PursuitChild.Opportunity__c); 
    system.debug(ParentOpp);
    }

When I look for the debug of ParentOpp, it does return all of the fields and values as expected:
 
14:21:18:203 USER_DEBUG [15]|DEBUG|Opportunity:{Name=Pursuit Survey Process, Id=006e000000An8XJAAZ, StageName=Pursuing, Priority__c=Target, RecordTypeId=012i00000002n45AAA}

When I try and call the StageName in my visualforce page with: 
Opportunity Stage: <apex:outputfield value="{!ParentOpp.StageName}" />

Nothing is rendered. It remains a blank space (and I'll write your name....to all the Taylor fans).

Thanks so much for any help!

Richard 
Hi,

I have a custom visualforce page with a working save and insert button for a custom child object of opportunities. 

However, I'm running into an issue with the save and redirect when going back in to view/edit the record. I've overriden the custom object's view button to direct to a copy of the existing visualforce page. This one only has a button to update the record instead of inserting a new one. Looking at the debug logs the parent opportunity ID never seems to get passed through and then the page reference returns null. 

How do I go about getting that ID so I can return users to the page they came from?

Thanks!

Controller Extension: 
public with sharing class SurveyParentIDExt{
    public Pursuit_Survey__c OpportunityParent{get;set;}
    
    public SurveyParentIDExt(ApexPages.StandardController controller){
        OpportunityParent=(Pursuit_Survey__c)controller.getRecord();
        system.debug(OpportunityParent);
        String parentID = System.currentPagereference().getParameters().get('parentid');
        OpportunityParent.Opportunity__c=parentid;        
    system.debug(parentid);
    
    }
       public PageReference doSaveWithRedirect(){
        Upsert OpportunityParent;
           system.debug(opportunityparent);
        PageReference ref = new PageReference('/' + System.currentPagereference().getParameters().get('parentid'));
           system.debug(ref);
        ref.setRedirect(true);
        return ref;
    }
    public PageReference saveandUpdate(){
        Update OpportunityParent;
        system.debug(OpportunityParent);
        PageReference ref = new PageReference('/' + System.currentPagereference().getParameters().get('parentid'));
        system.debug(ref);
        ref.setRedirect(true);
        return ref;
       
    }
}

Visualforce Page
 
<apex:page standardController="Pursuit_Survey__c" extensions="SurveyParentIDExt">

<apex:form >
..
..
..
 [Skipping the body to keep this shorter]

  <apex:commandButton  value="Update Responses" action="{!saveandUpdate}" />
</apex:form>
</apex:page>

 
Hi,

I have a custom controller for a visualforce page that contains a flow. I'm not sure where to even start to write a test class for it. Any help would be most appreciated! 

What I have is a custom object, Project Information, that has a record created through the flow. The exit page is then set to the newly created record's page. ProjInfoID is a variable within the flow. 
public class ProjInfoFlowController {

    public Flow.Interview.CreateProjInfo myFlow { get; set; }
    
    public String getmyID() {
        if (myFlow==null) return '';
        else return myFlow.ProjInfoID;
        }
    
    public PageReference getOID(){
        PageReference p = new PageReference('/' + getmyID());
        p.setRedirect(true);
        return p;
        }

}

 
I'm getting my feet wet trying to write my first trigger and like many others am running into some errors. 

We have a custom object, Project Information, that is a child in a master-detial lookup to opportunities. I have a user lookup field on both opportunities and project information that I want to keep in sync with each other. Changes to the lookup only occur on the Opportunity record. 

I'm getting an error on the code below on line 4 (obj.REO_User_Record__c=Opportunity.REO__c;), "I'llegal assignemtn from Schema.SObjectField to Id. How do I get the UserID from the opportunity lookup into the Project Information lookup?

Thanks for the help!
 
trigger UpdateREO on Opportunity (after update,after insert) {
	List<Project_Information__c>IstToUpdate=new List<Project_Information__c>();
    for(Project_Information__c obj :[select id,name,REO_User_Record__c,Opportunity__c from Project_Information__c where Opportunity__c != null and Opportunity__c in : trigger.new]){
        obj.REO_User_Record__c=Opportunity.REO__c;
        IstToUpdate.add(obj);        
    }
    if(!IstToUpdate.isEmpty())
        update IstToUpdate;
    
}

 
Hi,

I'm trying to determine if it's possible to have a popup box/window with a picklist appear when an opportunity is saved if the stage equals won or lost. Within the window we also need to save another field to the opportunity record. 

We're trying to get users to input this data as it's fairly critical in evaluating our sales process. A validation rule was considered but due to internal company reasons will not be used.

Thanks in advance for any help!