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 

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

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.Please give one example..

RockzRockz

Hi..

 

Hope this will help :

 

Apex class which is further call by Custom List Button for execution of Batch :---

global with sharing class Batch_ExectionController { 

 //This method is to get the view mode   

 webservice static ID executeBatchForDeletionOfContact() {             

  Id batchProcessId;                 

  //Calling Constructor for Batch Execution       

  MyTrainingSurveyProcess dc = new MyTrainingSurveyProcess();   

  batchProcessId = Database.executeBatch(dc);         

  System.debug('Returned batch process ID:@@@@@@@@@@@@@@@@@@ ' + batchProcessId);    
  return batchProcessId;   

 }

}

 

  Here ustom List Button Code:

 

Custom List Button Code:--


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

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

//Calling Class and Method

var contextUser = sforce.apex.execute("Batch_ExectionController", "executeBatch", {});

window.alert('Now Please check Debug logs');

 

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them.

 

Thnaks,

Cool Sfdc

 

 

 

neshnesh

I want to  Calling Apex Class from List Custom Button and how to cover below logic using apex class. i already complete schedule process logic.
A)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)logic using apex class.Please give one example..

neshnesh

public with sharing class Trainingsurveylistbutton {
public List<training__c> t2;
public set<id>Set1;
public boolean pageblockCheck{set;get;}
    public Trainingsurveylistbutton(ApexPages.StandardSetController controller) {
   
    t2 = new list <training__c>();

// t2 list method
    t2=Controller.getSelected();
    if(t2.size()<=0)
        {
      when i click button  without select record...how to add error msg to training list view page(standard page)-not new vf page--please give ur idea.here.
    //   ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.WARNING, 'Please select atleast one record from list view you wish to update');  
          //  ApexPages.addMessage(errMsg);

        }else{
  
        Set1 = New set<id>();
            for(training__c ss : t2){
                system.debug('::::ss.Id::::'+ss.Id);
                Set1.add(ss.id);
            }

 
}
    }
    public void surveylist()
    {
    // 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>();

 here i want to add logic here:

1.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)


       t1 = [ select day1surveyflag__c,T__c, day3surveyflag__c, day5surveyflag__c from training__c where day1surveyflag__c = true or day3surveyflag__c = true or day5surveyflag__c = true or T__c='Day 1' ];
       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';
               }
             ts2.add(ts); 
          } 
        if(ts2 != null )
         {
           insert ts2;  
         } 
      
   
    }

}
----------------------------------------------------------------

Training survey process:

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.