+ Start a Discussion
jburnsSTjburnsST 

VF Page command buttons to invoke extension methods

I am building a tabbed layout for an application we are building,due to the large number of related objects to keep things organized.

 

We have multiple custom buttons on our custom objects which execute apex class methods and perform javascript functions. Here is an example :

 

 

{!requireScript("/soap/ajax/13.0/connection.js")} 

try
{
var leadId = "{!Lead__c.Id}";
sforce.apex.execute("ActivityClass", "AddDisposition", {recordId:leadId, objectType:"Lead"});
window.location.reload();
}
catch(err)
{
alert("Error logging disposition: " + err.toString());
}

 How would I duplicate this button in visual force?

 

I tried includng the class as an extention in the VF page:

 

<apex:page id="tabLayout" showHeader="true" standardstylesheets="false" standardController="Lead__c" extensions="ActivityClass">

 But when I call the method:

 

<apex:commandButton value="Log Disposition"  action="{!AddDisposition}"/>

 I received: Save error: /apex/tabLayoutLead @36,79 action="#{AddDisposition}": Unknown method 'Lead__cStandardController.AddDisposition()'

 

I have included both the ActivityClass and the tabbed VF page below:

 

ActivityClass:

 

/*
	Class summary: Functionality for logging dispositions on client and lead records
	Last modified by: J. Duhaney
	Last modified on: 11/8/2011
*/
global class ActivityClass {
	
	public static Boolean AddDisposition(List<Client__c> clients)
	{
		List<Task> tasks = new List<Task>();
		
		for (Client__c client : clients)
		{
			if (client.Disposition__c != null)
			{
				Task task = new Task();
				task.OwnerId = client.LastModifiedById;
				task.Subject = client.Disposition__c;
				task.WhatId = client.Id;
				task.Description = client.Notes__c;
				
				task.Priority = 'Normal';
				task.Status = 'Completed';
				task.ActivityDate = date.today();
				tasks.add(task);
				
				client.Disposition__c = '';
				client.Notes__c = '';
			}
		}
		
		insert tasks;
		update clients;
		return true;
	} 
	
	public static Boolean AddDisposition(List<Lead__c> leads)
	{
		List<Task> tasks = new List<Task>();
		
		for (Lead__c lead : leads)
		{
			Task task = new Task();
			task.OwnerId = lead.LastModifiedById;
			task.Subject = lead.Disposition__c;
			task.WhatId = lead.Id;
			task.Description = lead.Notes__c;
			
			task.Priority = 'Normal';
			task.Status = 'Completed';
			task.ActivityDate = date.today();
			tasks.add(task);
			
			lead.Disposition__c = '';
			lead.Notes__c = '';
		}
		
		insert tasks;
		update leads;
		return true;
	} 

	webservice static Boolean AddDisposition(Id recordId, String objectType)
	{
		if (objectType == 'Client')
		{
			List<Client__c> clients = [SELECT LastModifiedById, Disposition__c, Notes__c FROM Client__c 
									WHERE Id = :recordId];
		
			return AddDisposition(clients);
		}
		else if (objectType == 'Lead')
		{
			List<Lead__c> leads = [SELECT LastModifiedById, Disposition__c, Notes__c FROM Lead__c 
									WHERE Id = :recordId];
		
			return AddDisposition(leads);
		}
		else
		{
			return false;
		}
	}
	
	// Tests the add disposition functionality
	public static testMethod void TestAddDisposition()
    {    	
    	Client__c testClient = Unit_Tests.CreateTestClient();
    	testClient.Notes__c = 'Test notes';
    	testClient.Disposition__c = 'Email Sent';
    	upsert testClient;
    	
    	AddDisposition(testClient.Id, 'Client');
    	
    	Lead__c testLead = Unit_Tests.CreateTestLead();
    	testLead.Notes__c = 'Test notes';
    	testLead.Disposition__c = 'Email Sent';
    	upsert testLead;
    	
    	AddDisposition(testLead.Id, 'Lead');
    }
}

 

 

VF Tabbed Layout:

 

<apex:page id="tabLayout" showHeader="true" standardstylesheets="false" standardController="Lead__c" extensions="ActivityClass">
     <style>
     .tabStyle
     {
     	background-color: white ;
     }
    .activeTab {background-color: #1797c0 ; color:white; background-image:none}
    .inactiveTab { background-color: lightgray; color:black; background-image:none}
    </style>
    <script type="text/javascript">
function create()

window.open("{!Lead__c.Contract_URL__c}",'name','height=450,width=650');

</script>
  	    
	<apex:sectionHeader title="Lead ({!Lead__c.Name})" subtitle="{!Lead__c.First_Name__c} {!Lead__c.Last_name__c}" />
	<apex:toolbar id="theToolbar" height="50px;" itemSeparator="none" style="background-color:#1797c0;background-image:none">
        <apex:form >
        <apex:toolbarGroup itemSeparator="none" id="toobarGroupLinks">
            
            <apex:outputLabel >Disposition</apex:outputLabel>
		<apex:inputField value="{!Lead__c.Disposition__c}" style="width: 300px; height: 25px" />
		<apex:outputLabel >Disposition Notes</apex:outputLabel>
		<apex:inputField value="{!Lead__c.Notes__c}" style="width: 300px; height: 25px" />
		
        </apex:toolbarGroup>
       </apex:form>
    </apex:toolbar>   
	
	<apex:pageBlock > 
	
	 <apex:pageBlockButtons >
      <apex:form >
      <apex:commandButton value="Create Contract"  onclick="create()" />
      <apex:commandButton value="Log Disposition" action="{!AddDisposition}"/>
      </apex:form>
      </apex:pageBlockButtons> 
     
	
		<apex:pageBlockSection title="Client Information" columns="2" collapsible="true">
		<apex:outputField value="{!Lead__c.First_Name__c}" />
		<apex:outputField value="{!Lead__c.CO_First_Name__c}" />
		
		<apex:outputField value="{!Lead__c.Last_name__c}" />
		<apex:outputField value="{!Lead__c.CO_Last_Name__c}" />
		</apex:pageBlockSection>
		
		
	<apex:pageBlockSection columns="1" collapsible="true">
    <apex:tabPanel switchType="lead__c" selectedTab="actTab" id="tabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab">
        
		<apex:tab label="Activity" name="actTab" id="actTab">
			<apex:relatedList list="OpenActivities" />
			<apex:relatedList list="ActivityHistories" />
		</apex:tab>
		<apex:tab label="Quote" name="qTab" id="qTab">
		
		<apex:relatedList list="Quote__r" />
		<apex:iframe id="q" height="520px">
			</apex:iframe>
		</apex:tab>
		<apex:tab label="Debts" name="debtTab" id="debtTab">
			<apex:include pageName="addDebt"> </apex:include>
			<apex:relatedList list="Lead_Debt__r" />
			<apex:iframe id="ld" height="350px">
			</apex:iframe>
		</apex:tab>
		<apex:tab label="Financial Profile" name="finTab" id="finTab">
			<apex:relatedList list="Financial_Profiles__r" />
			<apex:iframe id="fp" height="1050px">
			</apex:iframe>
		</apex:tab>
        <apex:tab label="Personal Information" name="piTab" id="piTab">
	
			<apex:page standardController="Lead__c">
<apex:form >

<apex:pageBlock title="Personal Information" >
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection columns="2">
<apex:inputField value="{!Lead__c.First_Name__c}"/>
<apex:inputField value="{!Lead__c.Last_name__c}"/>
<apex:inputField value="{!Lead__c.MI__c}"/>
<apex:inputField value="{!Lead__c.Address_Line_1__c}"/>
<apex:inputField value="{!Lead__c.Address_Line_2__c}"/>
<apex:inputField value="{!Lead__c.City__c}"/>
<apex:inputField value="{!Lead__c.State__c}"/>
<apex:inputField value="{!Lead__c.Postal_Code__c}"/>
<apex:inputField value="{!Lead__c.Email_Address__c}"/>
<apex:inputField value="{!Lead__c.Best_Phone__c}"/>
<apex:inputField value="{!Lead__c.Cell_Phone__c}"/>
<apex:inputField value="{!Lead__c.Home_Phone__c}"/>
<apex:inputField value="{!Lead__c.Work_Phone__c}"/>
<apex:inputField value="{!Lead__c.MAIDEN__c}"/>
<apex:inputField value="{!Lead__c.Social_Security_Number__c}"/>
<apex:inputField value="{!Lead__c.DOB__c}"/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Co-Debt Information"/>
<apex:outputPanel >
<apex:inputField value="{!Lead__c.CODEBTINFO__c}">
<apex:actionSupport event="onchange" rerender="Personal Information" status="status"/>
</apex:inputField>
<apex:actionStatus startText="applying value..." id="status"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:actionRegion>

<apex:pageBlockSection rendered="{!Lead__c.CODEBTINFO__c == 'CO Info is the same'}">
<apex:inputField value="{!Lead__c.CO_Work_Phone__c}"/>
<apex:inputField value="{!Lead__c.CO_Cell_Phone__c}"/>


<apex:inputField value="{!Lead__c.CO_Work_Phone__c}"/>

<apex:inputField value="{!Lead__c.CO_Last_Name__c}"/>
<apex:inputField value="{!Lead__c.CO_POSTAL__c}"/>
<apex:inputField value="{!Lead__c.CO_Social_Security_Number__c}"/>
<apex:inputField value="{!Lead__c.CO_MI__c}"/>

<apex:inputField value="{!Lead__c.CO_ST__c}"/>







<apex:inputField value="{!Lead__c.CO_Home_Phone__c}"/>
<apex:inputField value="{!Lead__c.CO_Phone_Number__c}"/>


<apex:inputField value="{!Lead__c.CO_ADDLINE2__c}"/>


<apex:inputField value="{!Lead__c.CO_CITY__c}"/>
<apex:inputField value="{!Lead__c.CO_First_Name__c}"/>

<apex:inputField value="{!Lead__c.CO_Email_Address__c}"/>
<apex:inputField value="{!Lead__c.CO_ADDLINE1__c}"/>
<apex:inputField value="{!Lead__c.CO_MAIDEN__c}"/>

<apex:inputField value="{!Lead__c.CO_DOB__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page> 

		</apex:tab>
		<apex:tab label="Banking Information" name="bankTab" id="bankTab">
			<apex:form >
			<apex:pageBlockSection >
			<apex:inputField value="{!Lead__c.Bank_Name__c}"/>
			<apex:inputField value="{!Lead__c.Account_Number__c}"/>
			<apex:inputField value="{!Lead__c.Name_On_Account__c}"/>
			<apex:inputField value="{!Lead__c.Account_Type__c}"/>
			</apex:pageBlockSection>
			</apex:form>
			</apex:tab>
			<apex:tab label="Lead Detail" name="ldTab" id="ldTab">
			<apex:form >
			<apex:pageBlockSection >
			<apex:outputField value="{!Lead__c.Id}"/>
			<apex:outputField value="{!Lead__c.CreatedBy.Name}"/>
			<apex:outputField value="{!Lead__c.LastModifiedBy.Name}"/>
			<apex:outputField value="{!Lead__c.Name}"/>
			<apex:inputField value="{!Lead__c.Owner.Name}"/>
			<apex:inputField value="{!Lead__c.Source__c}"/>
			<apex:outputField value="{!Lead__c.Lead_Age__c}"/>
			<apex:inputField value="{!Lead__c.Lead_Status__c}"/>
			<apex:inputField value="{!Lead__c.Sub_Status__c}"/>
			<apex:inputField value="{!Lead__c.Legal_Status__c}"/>
			</apex:pageBlockSection>
			</apex:form>
			</apex:tab>
				<apex:tab label="Attachments" name="attTab" id="attTab">
	
		<apex:relatedList list="NotesAndAttachments" />
			
		</apex:tab>
		
				<apex:tab label="Log" name="logTab" id="logTab">
	
		<apex:include pageName="leadHistory"> </apex:include>
			
		</apex:tab>
		
		
		
      
        
    </apex:tabPanel> 
	</apex:pageBlockSection>
    </apex:pageBlock>
	 
</apex:page>

 

Thank You in advance for any help,

 

Jason Burns

IspitaIspita

Hi Jason,

in your code for your apex page :-

VF page code :-

<apex:page id="tabLayout" showHeader="true" standardstylesheets="false" standardController="Lead__c" extensions="ActivityClass">

 

You have mentioned Lead__c as the standard controller.

so when you call the methos as below:-

 

<apex:commandButton value="Log Disposition"  action="{!AddDisposition}"/>

 

Salesforce will try to find the function in the standard controlled where it does not exist.

 

So check the code below how an extension class method is being called in one's controller:-

 Extension class:-

public ZillowTypes.PropertySearchResponse searchZillow( String address, String citystatezip ){
  // construct the URL     
  String endpointURL = ZillowConfig.PROPERTY_SEARCH_URL + ZillowConfig.ZWSID + '&address=' +    EncodingUtil.urlEncode(address, 'UTF-8') + '&citystatezip=' + EncodingUtil.urlEncode(citystatezip, 'UTF-8') ;                     
  ZillowTypes.PropertySearchResponse searchResponse = null ;      
  try{         
    HttpResponse response = invokeZillow( 'GET', endpointURL ) ;
    XMLDom responseXML = new XMLDom( response.getBody() ) ;
    String code = responseXML.getElementByTagName('code').nodeValue ;
    if( code == ZillowTypes.CODE_SUCCESS){
                searchResponse = new ZillowTypes.PropertySearchResponse( responseXML.getElementByTagName('response') ) ;
     }
     else{
        throw new ZillowTypes.ZillowException( 'Error in Zillow response - code = '+code +' Description : ' +ZillowTypes.PropertySearchResponseCode.get(code) );  
      }
  }
  catch( System.Exception e){
    System.debug( 'Error ' +e) ;
    throw e ;
  }        
  return searchResponse ;     
}

 this how you need to code a method inyour custom controller class so perhaps you need to use a custom controller:-

 

try{
ZillowService zillow = new ZillowService() ;
// search Zillow for property at 2114 Bigelow Ave, Seattle, WA
ZillowTypes.PropertySearchResponse result = zillow.searchZillow( '2114 Bigelow Ave', 'Seattle, WA') ;

}

 

 Hope this helps..

 

jburnsSTjburnsST

I am not sure I understand at all lol, can you explain a bit more?

Salesforc expertSalesforc expert
I m also ?