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 Button1.Please give ur idea

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

---------------

public with sharing class Trainingsurveylistbutton {
public List<training__c> t2;
public set<string> Set1;
public boolean pageblockCheck{set;get;}
//public List<training__c> l1 = New List<training__c>();
    public Trainingsurveylistbutton(ApexPages.StandardSetController controller) {
   
    t2 = new list <training__c>();
    t2=Controller.getSelected();
    system.debug('++++++++++T2::::'+t2);
    if(t2.size()<=0)
        {
       //for(training__c s1 : t2){
       //s1.addError('Please select atleast one record from list view you wish to update');
       // }
       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{
  
      Here i am used set- to get all selected record id  . but i want to get all selected record field .. how to get selected record  under all field .Please give ur idea.i want to use those selected record field -below surveylist() method.i have marked red
            set1 = New set<string>();
           for(training__c ss : t2){
               system.debug('::::ss.Id::::'+ss);
               // Set1.add(ss.ID);
               system.debug('++++++++++set1'+set1);
            }

 
}
    }
    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>();
       t2 = [ select id,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(string lx : set1)
      {  
        system.debug('*********lx'+lx);
        
        training_survey__c ts = new training_survey__c();
        training__c tr = new training__c();
     
        integer ts1=[select count() from training_survey__c where Training__c =: lx];
        system.debug('**count'+ts1);
        if(ts1==1)
        {
        
          ts=[select id,Training__c,survey_type__c from training_survey__c where Training__c =: lx];
          
          system.debug('*************ts'+ts.survey_type__c);
               
              if(ts.Survey_Type__c == 'Day1') 
              {
                ts.sample__c = 'one day';
              }
          //   ts2.add(ts);
          }
          update ts;
           system.debug('*************ts'+ts.survey_type__c);

     //   if(ts2 != null )
     //              {
      //                  update ts2;  
      //             } 
        
        if (ts1==0)
                {    
                   ts.training__C = lx;
                   ts.Survey_Type__c = 'Day1';
                // }
                   ts2.add(ts); 
                   
               if(ts2 != null )
                  {
                        insert ts2;  
                   } 
                 }
            }
       }

-------------------

please give your idea above code..

digamber.prasaddigamber.prasad

Hi,

 

The only way I can think of is to use a VF page an on action of page tag, call the function of this class. Of course you have to make this class controller of the vf page.

 

Let me know if you have any specific question on this.

neshnesh

yes this is my vf page:

<apex:page standardController="Training__c" extensions="Trainingsurveylistbutton" action="{!surveylist}"  recordSetVar="list button"> 
<apex:messages style="text-align:center;color:red;"/>
</apex:page>
                                        

----------------------------------------------------------------

 

corresponding apex class:

 public with sharing class Trainingsurveylistbutton {
public List<training__c> t2;
public set<string> Set1;
public boolean pageblockCheck{set;get;}
//public List<training__c> l1 = New List<training__c>();
    public Trainingsurveylistbutton(ApexPages.StandardSetController controller) {
   
    t2 = new list <training__c>();
    t2=Controller.getSelected();
    system.debug('++++++++++T2::::'+t2);
    if(t2.size()<=0)
        {
       //for(training__c s1 : t2){
       //s1.addError('Please select atleast one record from list view you wish to update');
       // }
       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{
  
      Here i am used set- to get all selected record id  . but i want to get all selected record field .. how to get selected record  under all field .Please give ur idea.i want to use those selected record field -below surveylist() method.i have marked red
            set1 = New set<string>();
           for(training__c ss : t2){
               system.debug('::::ss.Id::::'+ss);
               // Set1.add(ss.ID);
               system.debug('++++++++++set1'+set1);
            }

 
}
    }
    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>();
       t2 = [ select id,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(string lx : set1)
      {  
        system.debug('*********lx'+lx);
        
        training_survey__c ts = new training_survey__c();
        training__c tr = new training__c();
     

 here i want to add logic here:please give ur idea:

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)


        integer ts1=[select count() from training_survey__c where Training__c =: lx];
        system.debug('**count'+ts1);
        if(ts1==1)
        {
        
          ts=[select id,Training__c,survey_type__c from training_survey__c where Training__c =: lx];
          
          system.debug('*************ts'+ts.survey_type__c);
               
              if(ts.Survey_Type__c == 'Day1') 
              {
                ts.sample__c = 'one day';
              }
          //   ts2.add(ts);
          }
          update ts;
           system.debug('*************ts'+ts.survey_type__c);

     //   if(ts2 != null )
     //              {
      //                  update ts2;  
      //             } 
        
        if (ts1==0)
                {    
                   ts.training__C = lx;
                   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.

Please give ur idea for that process or  i am used set above classes -(above  i am mentioned in red line)- to get all selected record id  . but i want to get all selected record field .. how to get selected record  under all field .Please give ur idea.i want to use those selected record field -below surveylist() method.i have marked red