0

I have a VF page that the user is directed too when they click on an opportunity and they are the opportunity owner. The page just asks the user simple compliance questions. It's working fine but on some opportunities, when the owner is on the VF page and they hit submit, instead of directing the user to the opportunity, it will just refresh the page and hang up and I have no clue why. It seems really random.

I'm having issues with the following code:

Controller:

public with sharing class ExportCheckPageController {

public boolean checkYes {get; set;}
public boolean checkNo{get; set;} 

private static final String SGI_OPP = 'SGI Opportunity'; 
private static final String SGI_APAC_OPP = 'SGI APAC Opportunity';

public Export_Check__c exportCheck {get; set;}
public Opportunity opp {get;set;}
private Account acc;
private Id sgiRT;
private Id apacRT;
private Id oppId;
private List<Export_Check__c> exportList = new List<Export_Check__c>();
private List<Opportunity> oppList = new List<Opportunity>();
private ApexPages.standardController controller;

public ExportCheckPageController(ApexPages.StandardController stdController){
    controller = stdController;
    checkYes = false;
    checkNo = false;
    exportCheck = new Export_Check__c();
    opp =(Opportunity)stdController.getRecord();
    oppId =stdController.getid();
    system.debug(oppId);

    if((ApexPages.currentPage().getParameters().get('oppId') != null) && (ApexPages.currentPage().getParameters().get('oppId') != '')){
        oppId = ApexPages.currentPage().getParameters().get('oppId');
        system.debug(oppId);
    }
    sgiRT = [SELECT Id FROM RecordType WHERE Name = 'SGI Opportunity'].Id;
    apacRT = [SELECT Id FROM RecordType WHERE Name = 'SGI APAC Opportunity'].Id;
    loadOppExports();
    system.debug(oppId);
}

public void loadOppExports(){
    if(oppId != null){
        //Add all other fields from opportunity i may need & from Opp Account
        //Gonna have to do a few more quries to get all info from acount and contacts
        opp = [Select Id, Name, OwnerId, Account.Id, isExportCompleted__c, (Select Id, Name, ExportStatus__c, CheckNO__c, CheckYes__c, OppExportCheck__c from Export_Checks__r) From Opportunity where id =: oppId];
        acc = [select Id, Owner.Id, Parent.Id, Parent.Name, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, 
               Street_Address__c, City__c, State_Province__c, Zip_Postal_Code__c, Country_Code__c, Account_Intergraph_Line_of_Business__c, Industry, Type, 
               Phone, Account_Category__c, RecordTypeId,(select Id, account.id, Name, firstname, lastname, account.name, Account_Industry__c, Department, 
                                                         MailingStreet, MailingCity, MailingPostalCode, MailingState, MailingCountry, Email, Phone from contacts) 
               from Account where account.id in (Select Opportunity.AccountId From Opportunity where id =: opp.id)];
        system.debug(opp);
        system.debug(acc);
        //Check List size - but there should only be one- maybe need to revisit this later
        if(!opp.Export_Checks__r.isEmpty()){
            for(Export_Check__c ec: opp.Export_Checks__r){
                if(ec.Id != null){
                    //exportCheck = new Export_Check__c();
                    exportCheck = ec;
                    exportCheck.OppExportCheck__c = ec.OppExportCheck__c;
                    system.debug(exportCheck.OppExportCheck__c);
                }
                else{
                    //exportCheck = new Export_Check__c();
                    exportCheck.OppExportCheck__c = opp.Id;
                    system.debug(exportCheck.OppExportCheck__c);
                }
            }
        }
        else{
            //exportCheck = new Export_Check__c();
            exportCheck.OppExportCheck__c = opp.Id;
            system.debug(exportCheck.OppExportCheck__c);
        }
    }
}

public PageReference redirect(){
    PageReference pr;

   // System.debug( 'OPP RECORD TYPE: ' + opp.RecordTypeId );
  //    System.debug( 'PASS RECORD TYPE?: ' + (opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT) );
  //    System.debug( 'OPP OWNER: ' + opp.OwnerId );
  //    System.debug( 'PASS OWNER?: ' + opp.OwnerId == UserInfo.getUserId() );
  //    System.debug( 'PASS BOTH?: ' + ((opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT) && opp.OwnerId == UserInfo.getUserId()) );

    if((opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT) && opp.OwnerId == UserInfo.getUserId() ){
        System.debug('Inside RTYPE and OWNER If Statement');
        if(!opp.isExportCompleted__c && exportCheck.Id == null){
            pr = new PageReference('/apex/ExportCheckPage1?oppId='+ opp.Id);
            pr.setRedirect(true); 
        }
    }
    else{
        System.debug('Inside Else Statement');
        pr = new PageReference('/' + opp.id);
        pr.getParameters().put('nooverride', '1');
    }
    return pr;
}     

public void setExportCheck(){
    if(checkYes){
        opp.isExportCompleted__c = false;
        exportCheck.Name = opp.Name;
        exportCheck.Company_Name__c = acc.Name;
        exportCheck.Country__c = acc.Country_Code__c;
        exportCheck.City__c = acc.City__c; 
        exportCheck.State__c = acc.State_Province__c;
        exportCheck.Street_1__c = acc.Street_Address__c;
        exportCheck.Zip__c = acc.Zip_Postal_Code__c;
        exportCheck.CheckYes__c = checkYes;
        exportCheck.CheckNO__c = checkNo;
        exportCheck.ExportStatus__c = 'Under Review';
        //eventually we will want to set all of Export Yes/No questions here

    }
    else if(checkNo){
        opp.isExportCompleted__c = true;
        exportCheck.Name = opp.Name;
        exportCheck.Company_Name__c = acc.Name;
        exportCheck.Country__c = acc.Country_Code__c;
        exportCheck.City__c = acc.City__c; 
        exportCheck.State__c = acc.State_Province__c;
        exportCheck.Street_1__c = acc.Street_Address__c;
        exportCheck.Zip__c = acc.Zip_Postal_Code__c;
        exportCheck.CheckNO__c = checkNo;
        exportCheck.CheckYes__c = checkYes;
        exportCheck.Export1__c = 'No';
        exportCheck.Export2__c = 'No';
        exportCheck.Export3__c = 'No';
        exportCheck.Export4__c = 'No';
        exportCheck.Export5__c = 'No';
        exportCheck.Export6__c = 'No';
        exportCheck.Export7__c = 'No';
        exportCheck.ExportStatus__c = 'Approved';

    }
    else{
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'You must select one of the Yes or No options below. '));
    }
    if(!exportList.isEmpty()){
        exportList.clear();
        exportList.add(exportCheck);
        system.debug(checkNo);
        system.debug(checkYes);
        system.debug(exportCheck);
        system.debug(opp);

    }
    else{
        exportList.add(exportCheck);
        system.debug(checkNo);
        system.debug(checkYes);
        system.debug(exportCheck);
        system.debug(opp);

    }
}
public PageReference startApproval(){
    //This method will start he approval process - Do an insert of an record and kick off the approval process.
    //Phase 1 - Start he approval process, display info messages on page to tell the user what the next steps to take
    //Phase 2 - Add Steps for the rest of the attachments to be completed in Salesforce and then send to Compliance team for approval
    //Phase 3 - Do a web service call out to Tradebeam to do export screening and and store this informationon the object. 
    Database.SaveResult[] insertEx;
    system.debug(exportList);
    system.debug(Limits.getHeapSize());
    system.debug(Limits.getLimitHeapSize());
    insertEx = database.insert(exportList, false);
    for (Database.SaveResult sr: insertEx){
        if(sr.isSuccess()){
            system.debug('Insert Succeeded. Export ID: '+ sr.getId());
        }
        else{
            for(database.Error err: sr.getErrors()){
                system.debug('The following error has occured. ');
                system.debug(err.getStatusCode() + ': ' + err.getMessage());
                system.debug('Error fields: ' + err.getFields());

            }
        }
    }
    try{
        system.debug(opp);
        update opp;
    }
    catch(DMLException ex){
        system.debug('Error+++ '+ ex);
    }

    PageReference redirect =  new PageReference('/apex/StandardOpportunity?id='+ opp.Id);
    redirect.setRedirect(true);
    return redirect;
    //return Page.StandardOpportunity;
}
}

VisualForce page:

 <apex:page standardController="Opportunity"        extensions="ExportCheckPageController" sidebar="false" showHeader="true" standardStylesheets="true" showChat="false">
<apex:sectionHeader title="Export Compliance Checklist Process" subtitle="{!opp.name}" description="Read through ALL of the following questions and select one of the options at the bottom of the page. 
                                                                                                                         For any question you can answer “Yes”, complete the action required.  
                                                                                                                         Where a Supplemental Export Checklist is required, complete the indicated 
                                                                                                                         Supplemental Export Checklist and submit with this Standard Export Checklist. To download a copy of the
                                                                                                                         Export Compliance Checklist please use the link below.
                                                                                                                         Contact information for the Export Compliance Manager is also located below."/>
<apex:outputLabel value="Export Compliance Manager Contact Information" style="font-weight:bold" /><p/>
<apex:outputText value="Email: " style="font-weight:bold"/> <apex:outputText value="sgiexportcompliance@intergraph.com"/><p/>
<apex:outputText value="Phone: " style="font-weight:bold"/> <apex:outputText value="1-256-730-1857" /><p/>
<apex:outputLink value="https://intergraph--testval--c.cs87.content.force.com/servlet/servlet.FileDownload?file=0158E000000LSgc" id="link" target="_blank">
    Export Compliance Checklist</apex:outputLink> <p/>
<apex:form id="exportForm" forceSSL="true" >
    <apex:pageBlock title="Export Checklist" mode="edit">
    <apex:inputHidden value="{!Opportunity.OwnerId}" id="theHiddenInput"/>
        <apex:inputHidden value="{!Opportunity.isExportCompleted__c}" id="theHiddenInput1"/>
        <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Submit" action="{!startApproval}" rendered="{!(checkYes || checkNo)}" immediate="true" reRender="exportForm" >
                <!--<apex:actionStatus id="status">
                    <apex:facet name="start">
                        <div style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; opacity: 0.25; z-index: 1000; background-color: black;">
                            &nbsp;
                        </div>
                        <div style="position: fixed; left: 0; top: 0; bottom: 0; right: 0; z-index: 1001; margin: 15% 50%">
                            <div style="display: inline-block; padding: 2px; background-color: #fff; width: 125px;">
                                <img src="/img/loading.gif" style="float: left; margin: 8px;" />
                                <span style="display: inline-block; padding: 10px 0px;">Please Wait...</span>
                            </div>
                        </div>
                    </apex:facet>
                </apex:actionStatus>
               <!-- <apex:actionSupport action="{!redirect2}" status="status" immediate="false" oncomplete="status"/>-->
            </apex:commandButton>
        </apex:pageBlockButtons>
        <apex:outputPanel id="checklistPanel" >
            <apex:pageBlockSection collapsible="false" columns="1" showHeader="true" title="Questions" >
                <apex:pageBlockSectionItem id="exportQ1" rendered="true" >
                    <apex:outputLabel value="Q1 - EMBARGOED COUNTRY SCREEN:" for="export1"/> 
                    <apex:outputText id="export1" value="Is any party to the transaction located in 
                                                         an Embargoed Country(Cuba, Iran, North Korea, Syria, North Sudan, or other country subject to a 
                                                         current trade embargo), or is any Item(s) destined for an Embargoed Country?" > 
                    </apex:outputText>
                </apex:pageBlockSectionItem>
                <!--<apex:PageBlockSectionItem >
                <apex:outputLabel for="exportQ1" value="Yes" rendered="{!checkYes}" />
                <apex:outputPanel layout="block">
                <apex:outputPanel layout="block" />
                <apex:inputCheckbox label="Yes" rendered="{!checkYes}" value="{!q1}" >
                <apex:actionSupport event="onselect"  rerender="checklistPanel" />
                </apex:inputCheckbox>
                </apex:outputPanel>
                </apex:PageBlockSectionItem>-->
                <apex:pageMessage detail="If yes, Contact the applicable Export Compliance Manager for further instructions." severity="warning" rendered="{!checkYes}" strength="3"/>

                <br/>
                <apex:pageBlockSectionItem id="exportQ2" rendered="true">
                    <apex:outputLabel value="Q2 - RESTRICTED PARTY SCREEN: " for="export2"/>
                    <apex:outputText id="export2" value="Do you have knowledge that the Customer/End User, or any other party to the transaction, is listed on any 
                                                         country’s Denied/Restricted Parties List, or is otherwise subject to sanctions?"/>
                </apex:pageBlockSectionItem>
                <apex:pageMessage detail="If yes, Contact the applicable Export Compliance Manager for further instructions." severity="warning" rendered="{!checkYes}" strength="3"/>
                <br/>
                <apex:pageBlockSectionItem id="exportQ3" rendered="true" >
                    <apex:outputLabel value="Q3 - DIVERSION RISK, “RED FLAGS” SCREEN:" for="export3"/>
                    <apex:outputText id="export3"  value="Is there any indicator that the Item(s) could be diverted to a different 
                                                          country or to a different End User, or are there any “Red Flags” present in 
                                                          connection with this Order?  "/>
                </apex:pageBlockSectionItem>
                <apex:pageMessage detail="If yes, Contact the applicable Export Compliance Manager for further instructions." severity="warning" rendered="{!checkYes}" strength="3"/>
                <br/>
                <apex:pageBlockSectionItem id="exportQ4" rendered="true" >
                    <apex:outputLabel value="Q4 - NUCLEAR SCREEN:" for="export4"/>
                    <apex:outputText id="export4"  value="Is the Customer/End User involved in any nuclear related industries or 
                                                          activities, or will the Item(s) beused in any such activity?"/>
                </apex:pageBlockSectionItem>
                <apex:pageMessage detail="If yes, Complete Nuclear Applicability Supplemental Export Checklist (Attachment D)" severity="warning" rendered="{!checkYes}" strength="3">
                    <apex:outputLink value="https://intergraph--testval--c.cs87.content.force.com/servlet/servlet.FileDownload?file=0158E000000LSgI" id="link" target="_blank">
                        Click to Download Attachment D</apex:outputLink> <p/>
                </apex:pageMessage>
                <br/>
                <apex:pageBlockSectionItem id="exportQ5" rendered="true" >
                    <apex:outputLabel value="Q5 - MISSILE SCREEN:" for="export5"/>
                    <apex:outputText id="export5" value="Is the Customer/End User involved in any missile-related activities (ex. design, development, or 
                                                         production of Rocket Systems (including ballistic missile systems and space launch vehicles and sounding 
                                                         rockets) and Unmanned Air Vehicles (including cruise missile systems, target drones and reconnaissance 
                                                         drones), or will the Item(s) be used in any such activity? "/> 
                </apex:pageBlockSectionItem>

                <apex:pageMessage detail="If yes, Complete Missile Technology Supplemental Export Checklist (Attachment E)" severity="warning" rendered="{!checkYes}" strength="3">
                    <apex:outputLink value="https://intergraph--testval--c.cs87.content.force.com/servlet/servlet.FileDownload?file=0158E000000LSgN" id="link" target="_blank">
                        Click to Download Attachment E</apex:outputLink> <p/>
                </apex:pageMessage>
                <br/>
                <apex:pageBlockSectionItem id="exportQ6" rendered="true" >
                    <apex:outputLabel value="Q6 - CHEMICAL OR BIOLOGICAL WEAPONS SCREEN:" for="export6"/>
                    <apex:outputText id="export6" value="Is the Customer/End User involved in the design, development, production, stockpiling or use of chemical 
                                                         or biological weapons, plants to make chemical weapons precursors, or will the Item(s) be used in any 
                                                         such activity?"/>
                </apex:pageBlockSectionItem>
                <apex:pageMessage detail="If yes, Complete Chemical or Biological Weapons Technology Supplemental Export Checklist (Attachment F)" severity="warning" rendered="{!checkYes}" strength="3">
                    <apex:outputLink value="https://intergraph--testval--c.cs87.content.force.com/servlet/servlet.FileDownload?file=0158E000000LSgS" id="link" target="_blank">
                        Click to Download Attachment F</apex:outputLink> <p/>
                </apex:pageMessage>
                <br/>
                <apex:pageBlockSectionItem id="exportQ7" rendered="true" >
                    <apex:outputLabel value="Q7 - RUSSIAN/UKRAINE SANCTIONS SCREEN:" for="export7"/>
                    <apex:outputText id="export7" value="Does the potential Order involve the supply of Item(s) or services intended to be used in, by, or for 
                                                         the benefit of (a) Russia, Crimea, or Sevastopol; (b) any party therefrom; (c) any subsidiary of a party 
                                                         listed in (b); or party acting on behalf of a party listed in (b)?  "/> 
                </apex:pageBlockSectionItem>
                <apex:pageMessage detail="If yes, Complete Ukraine-Related Sanctions Supplemental Export Checklist (Attachment G)" severity="warning" rendered="{!checkYes}" strength="3">
                    <apex:outputLink value="https://intergraph--testval--c.cs87.content.force.com/servlet/servlet.FileDownload?file=0158E000000LSgX" id="link" target="_blank">
                        Click to Download Attachment G</apex:outputLink> <p/>
                </apex:pageMessage>
                <br/>
                <apex:outputPanel id="check">
                    <apex:pageBlockSection collapsible="false" columns="2" title="Actions" > 
                        <apex:outputLabel value="You must select one of these options:" style="font-weight:bold" /> <p/> 
                        <br/>
                        <apex:pageBlockSectionItem id="y" rendered="true">
                            <apex:outputLabel value="Yes, One or more of the questions above apply: " for="checkYes" style="font-weight:bold; text-align:center" />
                            <apex:inputCheckbox id="checkYes" required="false" value="{!checkYes}" disabled="{!IF(checkNo, true, false)}">
                                <apex:actionSupport event="onclick"  rerender="checklistPanel, exportForm" action="{!setExportCheck}"/>
                            </apex:inputCheckbox>
                        </apex:pageBlockSectionItem>
                        <apex:pageBlockSectionItem id="n" rendered="true">
                            <apex:outputLabel value="No, None of the questions above apply:" for="checkNo" style="font-weight:bold; text-align:center"/>
                            <apex:inputCheckbox id="checkNo" required="false" value="{!checkNo}" disabled="{!IF(checkYes, true, false)}">
                                <apex:actionSupport event="onclick"  rerender="checklistPanel, exportForm" action="{!setExportCheck}" />
                            </apex:inputCheckbox>
                        </apex:pageBlockSectionItem> 
                        <apex:pageMessage detail="You have a compliance issue!! Please complete the defined action that apply's to any question that you could answer Yes too.
                                                  Clicking Submit will notify a compliance manager to start the review process. 
                                                  Please contact a Compliance Manager with the contact info above once you have submitted this checklist page." severity="warning" rendered="{!checkYes}" strength="3"/>
                        <apex:pageMessage detail="Please select Submit to continue. A compliance manager will be notified that you have completed this Export Checklist." severity="warning" rendered="{!checkNo}" strength="3"/>
                    </apex:pageBlockSection>
                </apex:outputPanel>
            </apex:pageBlockSection>
        </apex:outputPanel>
    </apex:pageBlock>
</apex:form>

0

I've had a similar issue. Try creating new instances/initializing your public attributes in the constructor,(specifically opplist or opp). This may not be the issue, but I had the same problem and this link:Page Will not redirect will show you how I fixed the problem.

| improve this answer | |
0

I've made a couple of updates with some comments for you to review. I'm seeing more SOQL calls than needed and variables not marked as transient that might cause loading issues.

public with sharing class ExportCheckPageController {

public boolean checkYes {get; set;}
public boolean checkNo{get; set;} 

private static final String SGI_OPP = 'SGI Opportunity'; 
private static final String SGI_APAC_OPP = 'SGI APAC Opportunity';

public transient Export_Check__c exportCheck {get; set;}
public transient Opportunity opp {get;set;}
private transient Account acc;
//private Id sgiRT;
//private Id apacRT;
private transient Map<Id, RecordType> recordTypes; // we don't need this in viewstate
private Id oppId;
private List<Export_Check__c> exportList = new List<Export_Check__c>(); // only variable needing to maintain viewstate for command button
private transient List<Opportunity> oppList = new List<Opportunity>();
private ApexPages.standardController controller;

public ExportCheckPageController(ApexPages.StandardController stdController){
    controller = stdController;
    checkYes = false;
    checkNo = false;
    exportCheck = new Export_Check__c();
    opp =(Opportunity)stdController.getRecord();
    oppId =stdController.getid();
    system.debug(oppId);

    if((ApexPages.currentPage().getParameters().get('oppId') != null) && (ApexPages.currentPage().getParameters().get('oppId') != '')){
        oppId = ApexPages.currentPage().getParameters().get('oppId');
        system.debug(oppId);
    }
    //put these into one RT list as you're only using it for checks later on
    //sgiRT = [SELECT Id FROM RecordType WHERE Name = 'SGI Opportunity'].Id;
    //apacRT = [SELECT Id FROM RecordType WHERE Name = 'SGI APAC Opportunity'].Id;
    recordTypes = new Map<Id, RecordType>([SELECT Id FROM RecordType WHERE Name = 'SGI Opportunity' OR Name = 'SGI APAC Opportunity']);
    loadOppExports();
    system.debug(oppId);
}

public void loadOppExports(){
    if(oppId != null){
        //Add all other fields from opportunity i may need & from Opp Account
        //Gonna have to do a few more quries to get all info from acount and contacts
        opp = [Select Id, Name, OwnerId, AccountId, isExportCompleted__c, (Select Id, Name, ExportStatus__c, CheckNO__c, CheckYes__c, OppExportCheck__c from Export_Checks__r) From Opportunity where id =: oppId];
        if(opp != NULL)
        {
            acc = [select Id, Owner.Id, Parent.Id, Parent.Name, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, 
               Street_Address__c, City__c, State_Province__c, Zip_Postal_Code__c, Country_Code__c, Account_Intergraph_Line_of_Business__c, Industry, Type, 
               Phone, Account_Category__c, RecordTypeId,(select Id, account.id, Name, firstname, lastname, account.name, Account_Industry__c, Department, 
                                                         MailingStreet, MailingCity, MailingPostalCode, MailingState, MailingCountry, Email, Phone from contacts) 
               from Account where account.id = opp.AccountId]; //you've already queried for this so don't need to query again
        }

        system.debug(opp);
        system.debug(acc);
        //Check List size - but there should only be one- maybe need to revisit this later
        // We can simplify this significantly, we know that we can't have a record in the database without an id
        // there for we can get rid of the id check. Also we know that if we have a Export Check, we are 
        // assigning the export check to our public variable, if not we are setting our export check
        /*if(!opp.Export_Checks__r.isEmpty()){

            for(Export_Check__c ec: opp.Export_Checks__r){
                if(ec.Id != null){
                    //exportCheck = new Export_Check__c();
                    exportCheck = ec;
                    exportCheck.OppExportCheck__c = ec.OppExportCheck__c;
                    system.debug(exportCheck.OppExportCheck__c);
                }
                else{
                    //exportCheck = new Export_Check__c();
                    exportCheck.OppExportCheck__c = opp.Id;
                    system.debug(exportCheck.OppExportCheck__c);
                }
            }
        }
        else{
            //exportCheck = new Export_Check__c();
            exportCheck.OppExportCheck__c = opp.Id;
            system.debug(exportCheck.OppExportCheck__c);
        }*/

        if(opp.Export_Checks__r.size() == 1)
        {
            exportCheck = opp.Export_Checks__r[0];
            exportCheck.OppExportCheck__c = exportCheck.OppExportCheck__c;
        }
        else
        {
            exportCheck.OppExportCheck__c = opp.Id;
        }
    }
}

public PageReference redirect(){
    PageReference pr;

   // System.debug( 'OPP RECORD TYPE: ' + opp.RecordTypeId );
  //    System.debug( 'PASS RECORD TYPE?: ' + (opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT) );
  //    System.debug( 'OPP OWNER: ' + opp.OwnerId );
  //    System.debug( 'PASS OWNER?: ' + opp.OwnerId == UserInfo.getUserId() );
  //    System.debug( 'PASS BOTH?: ' + ((opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT) && opp.OwnerId == UserInfo.getUserId()) );

    //if((opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT) && opp.OwnerId == UserInfo.getUserId() ){
    if((recordTyes.containsKey(opp.RecordTypeId)) && opp.OwnerId == UserInfo.getUserId() ){
        System.debug('Inside RTYPE and OWNER If Statement');
        if(!opp.isExportCompleted__c && exportCheck.Id == null){
            pr = new PageReference('/apex/ExportCheckPage1?oppId='+ opp.Id);
            pr.setRedirect(true); 
        }
    }
    else{
        System.debug('Inside Else Statement');
        pr = new PageReference('/' + opp.id);
        pr.getParameters().put('nooverride', '1');
    }
    return pr;
}     

public void setExportCheck(){
    if(checkYes){
        opp.isExportCompleted__c = false;
        exportCheck.Name = opp.Name;
        exportCheck.Company_Name__c = acc.Name;
        exportCheck.Country__c = acc.Country_Code__c;
        exportCheck.City__c = acc.City__c; 
        exportCheck.State__c = acc.State_Province__c;
        exportCheck.Street_1__c = acc.Street_Address__c;
        exportCheck.Zip__c = acc.Zip_Postal_Code__c;
        exportCheck.CheckYes__c = checkYes;
        exportCheck.CheckNO__c = checkNo;
        exportCheck.ExportStatus__c = 'Under Review';
        //eventually we will want to set all of Export Yes/No questions here

    }
    else if(checkNo){
        opp.isExportCompleted__c = true;
        exportCheck.Name = opp.Name;
        exportCheck.Company_Name__c = acc.Name;
        exportCheck.Country__c = acc.Country_Code__c;
        exportCheck.City__c = acc.City__c; 
        exportCheck.State__c = acc.State_Province__c;
        exportCheck.Street_1__c = acc.Street_Address__c;
        exportCheck.Zip__c = acc.Zip_Postal_Code__c;
        exportCheck.CheckNO__c = checkNo;
        exportCheck.CheckYes__c = checkYes;
        exportCheck.Export1__c = 'No';
        exportCheck.Export2__c = 'No';
        exportCheck.Export3__c = 'No';
        exportCheck.Export4__c = 'No';
        exportCheck.Export5__c = 'No';
        exportCheck.Export6__c = 'No';
        exportCheck.Export7__c = 'No';
        exportCheck.ExportStatus__c = 'Approved';

    }
    else{
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'You must select one of the Yes or No options below. '));
    }
    if(!exportList.isEmpty()){
        exportList.clear();
        exportList.add(exportCheck);
        system.debug(checkNo);
        system.debug(checkYes);
        system.debug(exportCheck);
        system.debug(opp);

    }
    else{
        exportList.add(exportCheck);
        system.debug(checkNo);
        system.debug(checkYes);
        system.debug(exportCheck);
        system.debug(opp);

    }
}
public PageReference startApproval(){
    //This method will start he approval process - Do an insert of an record and kick off the approval process.
    //Phase 1 - Start he approval process, display info messages on page to tell the user what the next steps to take
    //Phase 2 - Add Steps for the rest of the attachments to be completed in Salesforce and then send to Compliance team for approval
    //Phase 3 - Do a web service call out to Tradebeam to do export screening and and store this informationon the object. 
    Database.SaveResult[] insertEx;
    system.debug(exportList);
    system.debug(Limits.getHeapSize());
    system.debug(Limits.getLimitHeapSize());
    insertEx = database.insert(exportList, false);
    for (Database.SaveResult sr: insertEx){
        if(sr.isSuccess()){
            system.debug('Insert Succeeded. Export ID: '+ sr.getId());
        }
        else{
            for(database.Error err: sr.getErrors()){
                system.debug('The following error has occured. ');
                system.debug(err.getStatusCode() + ': ' + err.getMessage());
                system.debug('Error fields: ' + err.getFields());

            }
        }
    }
    try{
        system.debug(opp);
        update opp;
    }
    catch(DMLException ex){
        system.debug('Error+++ '+ ex);
    }

    PageReference redirect =  new PageReference('/apex/StandardOpportunity?id='+ opp.Id);
    redirect.setRedirect(true);
    return redirect;
    //return Page.StandardOpportunity;
}
}
| improve this answer | |
  • thank you for your response @techbusinessman. what does transient do? And I need the record types to only prompt users with certain record types. – user3708392 Feb 2 '16 at 20:42
  • Transient means the data in those variables are not transmitted in view state. This reduces the amount of data transmitted to the user round trip. I didn't see the rt usage in the vf page, that's why I had remove them. – techbusinessman Feb 2 '16 at 20:54
0

I've figured out the issue after testing. It hangs up because there are required fields on the opportunity that are not filled in and there are some picklist values that are no longer available to the user. These are mainly old opportunities that haven't been updated in a while.

| improve this answer | |

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.