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

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 8
    Replies
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!