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
neshnesh 

Please give ur idea for Calling Apex Class from List Custom Button

I have two object.Training and training survey...training record lookup relationship with training
survey.training object have training start date custom field...training survey have traning__c
lookup field.Traing survey have survey type custom field.
Process: if training start date --today+1,today+2,today+3--will send trainingsurvey email (day 1
or day 2 or day3 )to corresponding taining object record.else will send drop training survey.i
have set formula field check box..day 1 flag,day3,day5--whenever flag true -i have created
schedule process...apex class will insert survey type under traning survey object .i have created
workflow email alert -when will u insert survey type will send corresponding survey to corresponding records.

MY APEX LOGIC for schedule process.

global class MyTrainingSurveyProcess implements Schedulable
{
    global void execute(SchedulableContext SC)
    {
       // Sweep training object for day 2 , 3 & 5th day survey
       List <training__c> t1 = new list <training__c>();
       list <training_survey__c> ts2 = new list<training_survey__c>();
       t1 = [ select day1surveyflag__c, day3surveyflag__c, day5surveyflag__c from training__c where day1surveyflag__c = true or day3surveyflag__c = true or day5surveyflag__c = true ];
       for(training__c tx : t1)
          {
             training_survey__c ts = new training_survey__c();
             ts.training__C = tx.id;
             if(tx.day1surveyflag__c == true )
               {
                 ts.Survey_Type__c = 'Day1';
               }else
             if(tx.day3surveyflag__c == true )
               {
                 ts.Survey_Type__c = 'Day3';
               }else
             if(tx.day5surveyflag__c == true )
               {
                 ts.Survey_Type__c = 'Day5';
               }else
               {
                 ts.Survey_Type__c = 'Dropped';
               } 
             RecordType r = [Select id from Recordtype where sobjecttype = 'training_survey__c' and name= :ts.Survey_Type__c];
             ts.RecordTypeid = r.id;
             ts2.add(ts); 
          } 
        if(ts2 != null )
         {
           insert ts2;  
         }     
    }         
}
My requirement :
A)In case a past training survey was not created for a person and it is no longer within the
timeframes specified..- will send training survey -when click list button.
B)If a Survey record has already been created for the specific Day, we just need to resend the
existing survey record link..(purpose:survey was not filled by person within the
timeframes specified)
Here i need manual list view button on training object.i want to have 4 buttons that represent each survey.when i click list button(day1,day3,day5,drop) cover above(A&B) two logic.
i know list button creation.
How to Calling Apex Class from List Custom Button?.Please give ur idea for Calling Apex Class from List Custom Button and how to cover above (A&B)two logic using apex class.

Abhi_TripathiAbhi_Tripathi
Hi,

You can use this way to call your batch on list view

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

//Method Call
var status = sforce.apex.execute("Class_Name","Method_Calling_Your_Batch",{});

//Check for Batch Status
if(status == true || status == 'true') {
alert('Batch scheduled and you will be notified once completed.');
} else {
alert('Batch is already scheduled in the system.');
}