• Evannn
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

Hello,

 

I am a newbie Apex Developer trying to solve an issue with calling the StandardController.edit() method.

 

I created a custom Organization__c object for a user to enter info about their company.   I want logic in the class to limit t 1 instance of Organization__c, so I over-rode the "New" button on the object to point to a Visualforce page that calls my determinePageRedirect method.  If the list of Organization__c is > 0, it returns a PageReference to the edit page using the current ID.  If the list is null, I want to call StandardController.edit() to show the regular new page for Organization__c.  

 

Code works as expected when this.existingOrganization.size () > 0. however, I get an error message "cannot call edit() on null object when that list is empty. Seems like I need some mojo on my StandardController instantiation to make this work. Any ideas? Any help is greatly appreciated - this is driving me nuts!

 

Thanks

 

Apex Class

 

public class OrganizationValidation {

	//declare a private controller variable
	private ApexPages.StandardController controller;
	
	private Organization__c org {get;set;}
	
	//populate list of existingOrganizations
	public List<Organization__c> existingOrganizations;
		public List<Organization__c> getExistingOrganizations(){
			return existingOrganizations;	
	}

	//instatiate class
	public OrganizationValidation(){	
	}
	
	//standard controller constructor
	public OrganizationValidation(ApexPages.StandardController pController) {
        this.controller = pController;
        System.debug('***this.controller: ' +this.controller);
		
		//need StandardController to be aware of current context
		
		
		this.org = (Organization__c)pController.getRecord();
		System.debug('***org: '+ org);

    	OrganizationRedirect();
    }
    
	//Run these methods when we hit the Visualforce page
	public PageReference OrganizationRedirect(){
		
			
		//invoke method to query if there is an Organization__c result
		queryOrganizations();
		
		//invoke method to redirect based on if/then
		determinePageRedirect();
		
		return null;
	
	}
	
	//PageReference method – button on Visualforce page calls
	public PageReference editButtonRedirect() {

		PageReference editRedirect;
		for(Organization__c org: this.existingOrganizations){
				Organization__c myOrg = org;
				editRedirect = new PageReference ('/' + myOrg.id + '/e');
		
		}
	
		return editRedirect;
	
	}
		
	public void queryOrganizations(){
		//query the orgID
		this.existingOrganizations = [Select id, Name From Organization__c];
		//System debug
		System.debug('***existingOrganizations: '+existingOrganizations);
		
	}
	
	//Method to run if/else statement to redirect page
	public PageReference determinePageRedirect(){
	
		PageReference redirectPage;
		if (this.existingOrganizations.size() > 0){
			
			redirectPage = new PageReference ('apex/OrganizationRedirect');
			
		}else{
			
			//Show new page
			redirectPage = this.controller.edit();
			
		}
	
return redirectPage;
	
	}
}

 

Visualforce Page

 

<apex:page standardController="Organization__c" extensions="OrganizationValidation" action="{!determinePageRedirect}">
	<apex:outputPanel >
		<apex:form >
			<h1>Warning</h1>
			<p>You already entered your Organization's information.  Please edit the existing record.</p>
			<apex:commandButton action="{!editButtonRedirect}" value="Edit Organization" />
		</apex:form>
	</apex:outputPanel>
</apex:page>

 

 

 

 

 

Hi all,
 
I am new to Apex programming and am getting weird little error when i try to attach a PDF to Notes and Attachments.  I'm rendering a Visualforce page as a PDF, with an extension to an "EstimateProposal" Apex class.  The project compiles fine, but when I run it in the UI, I get an error "EXCEPTION_THROWN|[70,24]|System.VisualforceException: Too many nested getContent calls."  Funny thing is, the code block works when I execute it anonymously, just not it's part of my VF controller execution flow.  Anyone seen this before or could point me to a resource to fix it?  Any help would be greatly appreciated!
 
****APEX CLASS**** 
    public PageReference attachQuote() {
        PageReference pdfPage = Page.GenerateProposal;
        pdfPage.getParameters().put('id',this.opp.Id);
        Blob pdfBlob = pdfPage.getContent(); 
        Attachment proposalPDF = new Attachment (parentId = this.opp.Id, name=this.opp.name + '.pdf', body = pdfBlob);
        insert proposalPDF;
        return null;  
    } 
}
 

 
****VISUAL FORCE PAGE****
<apex:page standardController="Opportunity" extensions="EstimateProposal" renderAs="pdf" showHeader="false" sidebar="false" >
  • March 31, 2010
  • Like
  • 0

Hello,

 

I am a newbie Apex Developer trying to solve an issue with calling the StandardController.edit() method.

 

I created a custom Organization__c object for a user to enter info about their company.   I want logic in the class to limit t 1 instance of Organization__c, so I over-rode the "New" button on the object to point to a Visualforce page that calls my determinePageRedirect method.  If the list of Organization__c is > 0, it returns a PageReference to the edit page using the current ID.  If the list is null, I want to call StandardController.edit() to show the regular new page for Organization__c.  

 

Code works as expected when this.existingOrganization.size () > 0. however, I get an error message "cannot call edit() on null object when that list is empty. Seems like I need some mojo on my StandardController instantiation to make this work. Any ideas? Any help is greatly appreciated - this is driving me nuts!

 

Thanks

 

Apex Class

 

public class OrganizationValidation {

	//declare a private controller variable
	private ApexPages.StandardController controller;
	
	private Organization__c org {get;set;}
	
	//populate list of existingOrganizations
	public List<Organization__c> existingOrganizations;
		public List<Organization__c> getExistingOrganizations(){
			return existingOrganizations;	
	}

	//instatiate class
	public OrganizationValidation(){	
	}
	
	//standard controller constructor
	public OrganizationValidation(ApexPages.StandardController pController) {
        this.controller = pController;
        System.debug('***this.controller: ' +this.controller);
		
		//need StandardController to be aware of current context
		
		
		this.org = (Organization__c)pController.getRecord();
		System.debug('***org: '+ org);

    	OrganizationRedirect();
    }
    
	//Run these methods when we hit the Visualforce page
	public PageReference OrganizationRedirect(){
		
			
		//invoke method to query if there is an Organization__c result
		queryOrganizations();
		
		//invoke method to redirect based on if/then
		determinePageRedirect();
		
		return null;
	
	}
	
	//PageReference method – button on Visualforce page calls
	public PageReference editButtonRedirect() {

		PageReference editRedirect;
		for(Organization__c org: this.existingOrganizations){
				Organization__c myOrg = org;
				editRedirect = new PageReference ('/' + myOrg.id + '/e');
		
		}
	
		return editRedirect;
	
	}
		
	public void queryOrganizations(){
		//query the orgID
		this.existingOrganizations = [Select id, Name From Organization__c];
		//System debug
		System.debug('***existingOrganizations: '+existingOrganizations);
		
	}
	
	//Method to run if/else statement to redirect page
	public PageReference determinePageRedirect(){
	
		PageReference redirectPage;
		if (this.existingOrganizations.size() > 0){
			
			redirectPage = new PageReference ('apex/OrganizationRedirect');
			
		}else{
			
			//Show new page
			redirectPage = this.controller.edit();
			
		}
	
return redirectPage;
	
	}
}

 

Visualforce Page

 

<apex:page standardController="Organization__c" extensions="OrganizationValidation" action="{!determinePageRedirect}">
	<apex:outputPanel >
		<apex:form >
			<h1>Warning</h1>
			<p>You already entered your Organization's information.  Please edit the existing record.</p>
			<apex:commandButton action="{!editButtonRedirect}" value="Edit Organization" />
		</apex:form>
	</apex:outputPanel>
</apex:page>