• Salesforc expert
  • NEWBIE
  • 0 Points
  • Member since 2013

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

Hi all 

 

i am getting the above strange error ("System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out") on one custom button click in salesforce.what i did is just fetch the value  and then pass paramters to url in http get as shown below:

 

   public PageReference Clone() 
  {
    Test_Flight_Request__c clFR = new Test_Flight_Request__c(); 
    Test_Flight_Request__c oldFR = [SELECT From__c, To__c,Outbound_del__c,Pax_del__c,Region_del__c,    
        Inbound_del__c,Outbound_Flexibility__c,Inbound_Flexibility__c,Opportunity__c,
        Budget__c,Flight_Request_Type__c,Publish_Fare__c,Searcher__c,Notes__c,Email_To__c,Email_Content__c,
        Subject__c,Status__c,Miles__c,Internal_Flight__c,Approx_Tax__c,Searcher_Notes__c,Field1__c
       FROM Test_Flight_Request__c WHERE Id = :fr.Id];

    clFR.From__c = oldFR.From__c;
    clFR.To__c = oldFR.To__c;
    clFR.Outbound_del__c = oldFR.Outbound_del__c;
    clFR.Pax_del__c = oldFR.Pax_del__c;
    clFR.Region_del__c = oldFR.Region_del__c;
    clFR.Inbound_del__c = oldFR.Inbound_del__c;
    clFR.Outbound_Flexibility__c = oldFR.Outbound_Flexibility__c;
    clFR.Inbound_Flexibility__c = oldFR.Inbound_Flexibility__c;
    clFR.Opportunity__c = oldFR.Opportunity__c;
    clFR.Budget__c = oldFR.Budget__c;
    clFR.Publish_Fare__c = oldFR.Publish_Fare__c;
    clFR.Flight_Request_Type__c = oldFR.Flight_Request_Type__c;
    clFR.Notes__c = oldFR.Notes__c;
    
    clFR.Searcher__c = oldFR.Searcher__c;
    
    clFR.Email_To__c = oldFR.Email_To__c;      
    clFR.Email_Content__c = oldFR.Email_Content__c;
    clFR.Subject__c = oldFR.Subject__c;
    
    clFR.Status__c = oldFR.Status__c;
    clFR.Miles__c = oldFR.Miles__c;
    clFR.Internal_Flight__c = oldFR.Internal_Flight__c;
    clFR.Approx_Tax__c = oldFR.Approx_Tax__c;
    clFR.Searcher_Notes__c = oldFR.Searcher_Notes__c;
    clFR.Field1__c = oldFR.Field1__c;
    insert clFR;
    System.debug('Old FRId:'+oldFR.Id);
       System.debug('New FRId:'+clFR.Id);
       
    Http http = new Http();
       HttpRequest httpreq = new HttpRequest();
       httpreq.setEndpoint('http://abcs.com');
   
      httpreq.setMethod('GET');
      httpreq.setTimeout(60000);
      String responseBody='';
      if (!Test.isRunningTest())
      { 
      HttpResponse  httpres =  http.send(httpreq);
    
      }
      else
      {
       responseBody = '200,4,48.5,-123.67';
      }
      
        PageReference pr = new PageReference('/'+  Id);
        pr.setRedirect(true);
        return pr;
  }
  
 
Pleas help me.
 

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