function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
manav_mnvmanav_mnv 

Custom button to call Apex class....

Hi All

I have one urgent query, described below:
I have one custom object "Communication" with two record types 'Inbound' & 'Outbound'. I created one custom button on Inbound layout called 'Reply'.
Functianality on Reply button is:

functionality to Reply to a Communication is a custom 'Reply' button that has code to clone the original Communication record (thus preserving the original), change the Record Type to Outbound and open the new record in Edit view.

Just similar to mailing pattern to reply, the cloning record will contain the Subject, Recipient email, Message type, Reply content(these are the fields) to auto populate from Inbound record type record and in editable mode. and have below section in which the clone of original mail will come.

Please help me in solving this problem.

Regards
Manav 


 
Daniel BallingerDaniel Ballinger

One way to call an Apex method via a custom button is to bounce the user through a custom Visualforce page that has the standardController set to the same object that custom button is defiend on. The extensions will include the Apex class that defines the method you want to call. Finally, the action will be the method you want to call.

There is a basic example How to call Apex Class methods from Customer Button or Link? (https://help.salesforce.com/apex/HTViewSolution?id=000006031&language=en_US)

Another good post on the concept is in Calling Apex Class from Custom Button, And Then Refreshing List View (http://salesforce.stackexchange.com/a/5246/102). This includes the considerations you should make if working on a managed package that may go through securtiy review.

yvk431yvk431
You just want to clone the same record with a different recordtype with a button click, guess you dont even need a apex class or page for this kind of functionality. Create a detail page button in the following manner:

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 

var comobj = new sforce.SObject("Communication__c"); 
comobj.RecordTypeId = '012A000000xxxxx'; 
--any other data from the existin record using merge fields---
result = sforce.connection.create([comobj]); 
if(result[0].getBoolean("success")) 

parent.window.location = '/'+result[0].id + '\e?retURL={!Communication__c.id}'; 

else 

alert(result[0].errors.message); 



--yvk