I have the following code:
public with sharing class ExportCheckPageController {
public boolean checkYes {
get{if(checkYes == null)
checkYes = false;
return checkYes;}
set;}
public boolean checkNo{
get{if(checkNo == null)
checkNo = false;
return checkNo;}
set;}
/*public boolean q1{
get{if(q1 == null)
q1 = false;
return q1;}
set;} */
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;
exportCheck = new Export_Check__c();
opp = new Opportunity();
acc = new Account();
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, 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;
if(opp.RecordTypeId == sgiRT ){
if(!opp.isExportCompleted__c && exportCheck.Id == null){
pr = new PageReference('/apex/ExportCheckPage1?oppId='+ opp.Id);
pr.setRedirect(true);
}
}
else{
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;
}
}
and the requirements changed to add this line of code((opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT) && opp.OwnerId == UserInfo.getUserId() )
in the Redirect method and replace if(opp.RecordTypeId == sgiRT )
but now I get the error of: SObject row was retrieved via SOQL without querying the requested field: Opportunity.OwnerId
As you can see I am querying Opportunity.OwnerId in the SOQL query and I have the field listed in my VF page. I'm confused to why it is erroring out.
OwnerId
. And second I can't see you are usingopp.OwnerId
in any of your code.. Can you pls let us know in which line you are getting error?