• Thakkar Parth
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 13
    Questions
  • 25
    Replies
Hi ,

I'm new to integration . Have referred Salesforce documents but didnt understood much . I do not know where to start , I have a requirement to integrate Salesforce with Amazon S3 . So if anyone can help me with the sample code will be very useful . 

Also nice blogs ,useful links for integrations if given would be great.


Thanks,
Marc.
Hi,

Have a requirement where on clicking a button ( custom buttom )  it will take me to the Contact detail page with auto filled Account Name field.
Please help me . I'm confused and any sample code will work best for me . Thanks .Marc

I'm getting an error and not able to find solution . I'm trying to use best practice of trigger using trigger handler . Following is what I did uptil now . Anyone please help me to structure or help me with modification .Thanks in advance.



===Trigger===

trigger OpportunityTrigger on Opportunity (after update) {
   new OpportunityTriggerHandler().run();
}

=== Trigger Handler class ===
public virtual class TriggerHandler {

  public TriggerHandler() { }
  
  // main method that will be called during execution
  public void run() {

     // dispatch to the correct handler method
      if(Trigger.isAfter && Trigger.isUpdate) {
      this.afterUpdate();
    } 
  }

  // context-specific methods for override
  protected virtual void afterUpdate(){}
  protected virtual void afterDelete(){}
    
  // exception class
  public class TriggerHandlerException extends Exception {}

}

== OpportunityTriggerHancler Class== 

I'm getting error in this class .
public class OpportunityTriggerHandler extends TriggerHandler {

   List<Task> tasks = new List<Task>();
   List<Opportunity> Opps = Trigger.new;
   Map <Id, String> oppsOwner = new Map <Id, String> ();
   
   public OpportunityTriggerHandler() {}
  
   protected override void afterUpdate()
  {
    for (Opportunity opp : trigger.new)
    {
        // Check if the StageName has been changed
        if (opp.StageName != trigger.oldMap.get(opp.Id).StageName)
        {
            // get the owner ID's that have been affected
            oppsOwner.put(opp.ownerId, null);
        }
    }

    // Map the owner ID to it's email address
    for (User owner : [SELECT Id, Email FROM User WHERE Id = :oppsOwner.keySet()])
    {
        oppsOwner.put(owner.Id, owner.Email);
    }
        
  }
   
  }


How do i validate through trigger to see that the account and contact associated with an opportunity are correct ? Thanks in advance . Marc


trigger fieldUpdate on Opportunity (after update) {

   List<Task> tasks = new List<Task>();
   List<Opportunity> Opps = Trigger.new;
   Map <Id, String> oppsOwner = new Map <Id, String> ();
       // Go through every opportunity in the trigger
    for (Opportunity opp : trigger.new)
    {
        // Check if the StageName has been changed
        if (opp.StageName != trigger.oldMap.get(opp.Id).StageName)
        {
            // get the owner ID's that have been affected
            oppsOwner.put(opp.ownerId, null);
        }
    }

    // Map the owner ID to it's email address
    for (User owner : [SELECT Id, Email FROM User WHERE Id = :oppsOwner.keySet()])
    {
        oppsOwner.put(owner.Id, owner.Email);
    }
    
    
   for (Opportunity Opp : Opps)
   {
     if(opp.StageName == 'Closed Won' && trigger.oldMap.get(opp.Id).StageName != opp.StageName) {
     
     Task tsk = new Task(whatID = Opp.ID, Ownerid = Opp.OwnerId);
     tasks.add(tsk); 
    }  
   } 
   insert tasks;
    
 
    List <Messaging.SingleEMailMessage> emails = new List <Messaging.SingleEMailMessage> ();

    // Go again through every opportunity in the trigger
    for (Opportunity opp : trigger.new)
    {  
        // Only work with opportunities that have owners mapped to their email addresses (only those ones have their status changed)
        if (oppsOwner.get(opp.OwnerId) != null)
        {
            // Create an email message and add it to the list
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            List <String> toAddresses = new List <String> {oppsOwner.get(opp.ownerId)};
            // set it in meassage as
            mail.setToAddresses(toAddresses);
            mail.setSubject('Automated Email : Opportunity StageName Updated');
            String body = 'The status has been changed on the opportunity record with StageName ' + opp.StageName;
            mail.setPlainTextBody(body);
            emails.add(mail);
        }
    }
    Messaging.sendEmail(emails);
       
  }


I'm getting an error while displaying Highcharts . The error is : SCRIPT1007: Expected ']' at line 47,character 4. Pressing my head since hours and trying to solve but no luck yet :( .Really appreciate the help.Thanks in advance. Marc


==== Class ===

public class HighChartsController3
{
  public String[] total;
  public String[] gettotal()
  {
     String q = 'SELECT count(Id),Name Total FROM Account group by Name';
     AggregateResult[] agr =Database.query(q);
     String[] strarray = new String[agr.size()];
     for (AggregateResult ar : agr) 
     {
         strarray.add(String.valueof(ar.get('Total')));

     }            

     return strarray ;
   }


public String[] position;
public String[] getposition()
{

     String q = 'SELECT count(Id),Name FROM Opportunity group by Name';
     AggregateResult[] agr =Database.query(q);
     String[] strarray = new String[agr.size()];

      for (AggregateResult ar : agr)
      {
         strarray.add(string.valueOf(ar.get('Name')));
     }

     return strarray ;
     }
   }



    === Page ===

<apex:page controller="HighChartsController3">
  <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" />
  <script src="https://code.highcharts.com/highcharts.js"></script>
  <script src="https://code.highcharts.com/modules/exporting.js"></script>

   <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

  <Script>
    $(function () {
     $('#container').highcharts({
     chart: {
        type: 'column'
    },

    title: {
        text: 'Total # of Apllications vs # of Open Jobs'
    },

    xAxis: {
     categories: {!position}
    // categories: ['abc','parth','hello']        

    },

    yAxis: {
        allowDecimals: false,
        min: 0,
        title: {
            text: 'Number'
        }
    },

    tooltip: {
        formatter: function () {
            return '<b>' + this.x + '</b><br/>' +
                this.series.name + ': ' + this.y + '<br/>' +
                'Total: ' + this.point.stackTotal;
        }
    },

    plotOptions: {
        column: {
            stacking: 'normal'
        }
    },

    series: [{
        name: 'New',
        data: [5, 3, 4, 7, 2],
        stack: 'Application'
    }, {
        name: 'Schedule Interviews',
        data: [3, 4, 4, 2, 5],
        stack: 'Application'
    }, {
        name: 'Hired',
        data: [3, 4, 4, 2, 5],
        stack: 'Application'
    },{
        name: 'Rejected',
        data: [3, 4, 4, 2, 5],
        stack: 'Application'
    },

      {
        name : 'Total Applications',
        data : {!total}           
        //data : [100,200,300],
        stack : 'Total'
        }]
      });
   });

  </script>
</apex:page>


I have a requirement to get the datatable which has all the features like pagination,sorting etc. I did this through Visualforce but my the requirement is to go with Jquery .

The link I'm referring to is : http://www.datatables.net/

Can someone please help me to get this Jquery with Visualforce . I searched around and got many things but of no use. Please help me with the sample code . Would be of great help.

Thanks in advance,
Marc.
Can i use setOrgWideEmailAddressId(Id) to send the FROM address in my case. My requirement is to send an email FROM Owner to the particular Lead when the Lead Status is changed.

I've enabled Org Wide Addressed in the Org Setup. Please help.

trigger UpdateLeadStatus on Lead (after update) {
    Map <Id, String> leadsOwner = new Map <Id, String> ();

    // Go through every lead in the trigger
    for (Lead lead : trigger.new)
    {
        // Check if the status has been changed
        if (lead.Status != trigger.oldMap.get(lead.Id).Status)
        {
            // get the owner ID's that have been affected
            leadsOwner.put(lead.ownerId, null);
        }
    }

    // Map the owner ID to it's email address
    for (User owner : [SELECT Id, Email FROM User WHERE Id = :leadsOwner.keySet()])
    {
        leadsOwner.put(owner.Id, owner.Email);
    }

    List <Messaging.SingleEMailMessage> emails = new List <Messaging.SingleEMailMessage> ();

    // Go again through every lead in the trigger
    for (Lead lead : trigger.new)
    {  
        // Only work with leads that have owners mapped to their email addresses (only those ones have their status changed)
        if (leadsOwner.get(lead.OwnerId) != null)
        {
            // Create an email message and add it to the list
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            List <String> toAddresses = new List <String> {leadsOwner.get(lead.OwnerId)};
            mail.setToAddresses(toAddresses);
            mail.setSubject('Automated Email : Lead Status Updated');
            String body = 'The status has been changed on the lead record with ID ' + lead.Id;
            mail.setPlainTextBody(body);
            emails.add(mail);
        }
    }
    Messaging.sendEmail(emails);
}


I've written a trigger where a notification in form of an email is sent to the  Owner when the Lead Status field is changed .But the requirement was different and i did it to send email to the Owner which is not.

 A help in Trigger where the requirement is that, an email should be sent from the Owner to the particular Lead Please help me to achieve this..Below is the code.

Really appreciate the help.
trigger UpdateLeadStatus on Lead (after update) {
    Map <Id, String> leadsOwner = new Map <Id, String> ();

    // Go through every lead in the trigger
    for (Lead lead : trigger.new)
    {
        // Check if the status has been changed
        if (lead.Status != trigger.oldMap.get(lead.Id).Status)
        {
            // get the owner ID's that have been affected
            leadsOwner.put(lead.ownerId, null);
        }
    }

    // Map the owner ID to it's email address
    for (User owner : [SELECT Id, Email FROM User WHERE Id = :leadsOwner.keySet()])
    {
        leadsOwner.put(owner.Id, owner.Email);
    }

    List <Messaging.SingleEMailMessage> emails = new List <Messaging.SingleEMailMessage> ();

    // Go again through every lead in the trigger
    for (Lead lead : trigger.new)
    {   
        // Only work with leads that have owners mapped to their email addresses (only those ones have their status changed)
        if (leadsOwner.get(lead.OwnerId) != null)
        {
            // Create an email message and add it to the list
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
            List <String> toAddresses = new List <String> {leadsOwner.get(lead.OwnerId)};
            mail.setToAddresses(toAddresses); 
            mail.setSubject('Automated Email : Lead Status Updated'); 
            String body = 'The status has been changed on the lead record with ID ' + lead.Id; 
            mail.setPlainTextBody(body); 
            emails.add(mail);
        }
    }
    Messaging.sendEmail(emails);
}


Can anyone please help me out to get a tigger . I would like to change Status of a Lead  and notification should be sent from the owner of that lead .

I know notification can be sent using Workflow . But i dont know how to write Trigger.Help appreciated.

Thanks,
Marc
How do i get the Object Name and Field Names for my code ? In the Controller , i'm getting Objects based on the IF condition which is not dynamic .Can someone please help me to make the changes . I tried really hard to get this but still no luck from last many days.Appreciate help.

Thanks,
Marc


==== Controller===
public class HighchartsController
{ 
    
    public String ObjectName {get;set;}
  
    
     public String str;
     public String getStr()
     {
        String res = '';
            Integer i;
            //SOQL 
            res = '[';
            for(i=1;i<13;i++)
            res +=  '' + (i+1) +  ',';
            res += 12;
            res += ']';
            return  res;
        } 
        
      public String bar;
      public String getBar()
      {
          String str = '';
            Integer i;
            //SOQL 
            str = '[';
            for(i=1;i<13;i++)
            str +=  '' + i + ',';
            str += 12;
            str += ']';
            return  str;
      }
          
    public List<Integer> opp;
    public List<Integer> getOpp()
    {
        If(ObjectName=='Contact')
        {
          opp=new List<Integer>();
         String q = 'Select count(Id),parthv__Level__c from Contact where parthv__Level__c  IN(\'Secondary\',\'Primary\') group by parthv__Level__c';
         AggregateResult[] agr =Database.query(q);
         opp.add(Integer.valueof(agr[0].get('expr0')));
         opp.add(Integer.valueof(agr[1].get('expr0')));
         
        
        }
        
        else if(ObjectName=='Opportunity')
        {
        
         opp=new List<Integer>();
         String q = 'Select count(Id),StageName from opportunity where StageName IN(\'Closed Won\',\'Closed Lost\') group by StageName';
         AggregateResult[] agr =Database.query(q);
         opp.add(Integer.valueof(agr[0].get('expr0')));
         opp.add(Integer.valueof(agr[1].get('expr0')));
         
       }
       
       else if(ObjectName=='Account')
        {
        
         opp=new List<Integer>();
         String q = 'Select count(Id),Rating from Account where Rating IN(\'Hot\',\'Warm\') group by Rating';
         AggregateResult[] agr =Database.query(q);
         opp.add(Integer.valueof(agr[0].get('expr0')));
         opp.add(Integer.valueof(agr[1].get('expr0')));
         
       }
       
       
       return opp;  
    }
    public void setX()
    {}
  
     
   }

=== Page ===

<apex:page standardController="Contact">
  <c:ModelChartUseComponent ObjName="Contact" />
  <!--    <c:ModelChartUseComponent sobj="{!Contact}" fieldsets="{!$ObjectType.Contact.FieldSets.ContactFields}" /> -->
</apex:page>

=== Component ===

<apex:component Controller="HighchartsController">

 <apex:attribute type="String" name="ObjName" required="true" assignTo="{!ObjectName}" description="Original poster failed to provide a useful description"/>

 <!-- Script here -->
   <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
     <script src="https://code.highcharts.com/highcharts.js"></script>
     <script src="https://code.highcharts.com/modules/exporting.js"></script>

     <div id="container" style="min-width: 310px; height: 400px; margin:0 auto"></div>

        <script>
            pieOrdinate = {!opp};   <!-- Get the Opportunities -->
           // pieOrdinate = ServerStr.split(',');
             $(function () {
             $('#container').highcharts({
             title: {
             text: 'Chart showing opportunities'
        },
        xAxis:{
                categories: ['Jan','Feb','Mar','Apr','May','Jun','July','Aug','Sept','Oct','Nov','Dec']
            },
              labels: {
              items: [{
            //  html: 'Opportunities',
              style: {
                    left: '50px',
                    top: '18px',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
                }
            }]
        },
        series: [ {
            type: 'column',
            name: 'Indian Railways',
            data: {!str}
            //data:[2,3,4,5,6]
        },
         {
            type: 'spline',
            name: 'Monthly Sales', // Average
           // data: [3, 2.67, 3, 6.33, 3.33],   
           data :{!bar},
            marker: {
                lineWidth: 2,
                lineColor: Highcharts.getOptions().colors[3],
                fillColor: 'white'
            }
        },
        {
            type: 'pie',
            name: 'Total consumption',
            data: [ {
              //  name: 'Lost',
                //y:23,
                y :parseInt(pieOrdinate[0]),
                sliced:true,
                selected:true,
                color: Highcharts.getOptions().colors[1] // Opp's Lost color
              }, 
               {
               // name: 'Won',
                y:parseInt(pieOrdinate[1]),
                color: Highcharts.getOptions().colors[2] // Opp's won color
              }],
               center: [100, 80],
               size: 100,
               showInLegend: false,
               dataLabels:
               {
                 enabled:true
               }
        }]
    });
});
  </script>
  <!-- End Default Content REMOVE THIS -->
</apex:component>




I've an issue while sorting date by arrow sorting. I successfully implemented this for "Subject" and "Status" field on Task object but while i click on Date column , it gives me error saying : unexpected token: <EOF> Error is in expression '{!toggleSort}' in page new_test_task_assignment: Class.PagingTasksController1.toggleSort: line 61, column 1

I've given endless try but still the same . Can anyone please help me to correct my mistake(s) .. Please help .

Thanks in advance.
 Marc   

public class PagingTasksController1{
    
    public List<Task> tasks {get;set;}
    public Task del;
    public Task taskDel;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit =3 ;
    public List<Task> lstTasks {get;set;}
    public String searchText {get;set;}
    public String rowIndex {get;set;}
    public Date mydate;
    public Integer totalCount {get;set;}
    public string sortField = 'Subject';  // default sort column
    private string sApplySOQL = '';
    public List<Task> delattendeeList {get;set;}
    
    public List<Task> delAttendees {get; set;}
    
    public PagingTasksController1(ApexPages.StandardController controller) {
        
        taskDel= (Task)controller.getRecord();
        tasks = [Select id,Subject,Status,ActivityDate,Owner.Name from Task];
        // this.Tasks=Tasks[0];
        totalCount = Tasks.size();
        
        delattendeeList = new List<Task>();
        delattendees = new List<Task>();
    }
    
    
    // the current sort direction. defaults to ascending
    public String sortDir {
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }
    
    // the current field to sort by. defaults to role name
    public String getsortField() {
        return sortField;
    }
    
    // the current field to sort by.
    public void setsortField(string value) {
        sortField = value;
    }
    
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
        
        integer iIndex = sApplySOQL.indexOf('Order By');
        if (iIndex > -1){
            sApplySOQL = sApplySOQL.substringBefore('Order By');
            sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir +  ' limit ' + QueryLimit + ' offset ' + OffsetSize;
        }
        
         System.debug('Before Sorted Date is ' +sApplySOQL);
         tasks = Database.query(sApplySOQL );  // here it where gives me error
         
    }
       
    public PagingTasksController1 (){
        //CountTotalRecords= [select count() from Task];
        //String qStr2= '7/23/2014';
        
    }
    
    /* public List<Task> getTasks(){
    if(tasks == null){
    tasks = new List<Task>();
    }
    return tasks;
    }  */
    
    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
    
    public void queryTasks(){
        
        String qStr2= searchText;
        String strnormal = '';
        try{
            mydate = date.parse(qStr2);
        }catch(Exception e)
        { }
        
        String strDate = '';
        if(mydate != null) {
            // strnormal = String.valueOf(mydate );
            String[] qstr3 = String.valueOf(mydate).split(' ',2);
            strDate = ' ActivityDate =  '+ qstr3[0] + ' ';
        }else{
            
            strDate  =  '(Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\' OR Owner.Name like \'%' +searchText+ '%\') ' + ' Order By '  + sortField;
        }
        
        String qStr = 'Select Owner.Name,Subject,Status,ActivityDate from Task where '+strDate+' limit ' + QueryLimit + ' offset ' + OffsetSize;
        System.debug(qStr);
        tasks = Database.query(qStr);
        
    }
    
    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
        }
    
    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
        }
    
    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }
    
    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }
    
    public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
    }
    
    public void deleteRow(){
        delete new Task(Id = rowIndex);
        for (Integer i = 0; i < Tasks.size(); i++) {
            if (Tasks[i].Id == rowIndex) {
                Tasks.remove(i);
                break;
            }
        }
    }
}

====== Page =====

<apex:page controller="PagingTasksController1" docType="html-5.0">
    <apex:form >
     <apex:variable var="rowNumber" value="{!0}"/>
        <apex:pageBlock title="Tasks" id="pgBlock" >
            <apex:pageBlockButtons >
               <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
               <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
            </apex:pageBlockButtons>
        <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                    hideOnEdit="editButton" event="ondblclick"
                    changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/> 
        <apex:inputText id="searchBox" value="{!searchText}"/>
        <apex:commandButton value="Search" reRender="pgTable,pgBlock" action="{!findTasks}"/>
        
        <apex:pageBlockTable value="{!Tasks}" var="tsk" id="pgTable">
           <apex:column headerValue="Action" >
              <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pgTable"> 
                 <apex:param name="rowIndex" value="{!tsk.id}" assignTo="{!rowIndex}" />
              </apex:commandButton>              
           </apex:column> 
           
        <!-- <apex:column headerValue="Action" >
          <apex:outputLink value="{!URLFOR($Action.Task.Delete, .id,['retURL'='/apex/New_Test_task_Assignment'])}"> Delete</apex:outputLink>
        </apex:column>  -->
        <apex:column headerValue="Subject">
            <apex:facet name="header">
                <apex:commandLink value="Subject" action="{!toggleSort}" rerender="pgTable" >
                  <apex:param name="sortField" value="Subject" assignTo="{!sortField}"/>
                    <apex:outputPanel rendered="{!BEGINS(sortField,'Subject')}">
                        &nbsp;<apex:image value="{!IF(sortDir = 'desc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                    </apex:outputPanel>
                </apex:commandLink>
            </apex:facet>     
          <apex:outputField value="{!tsk.Subject}"/>
        </apex:column>
           
        <apex:column headerValue="Status">
            <apex:facet name="header">
                <apex:commandLink value="Status" action="{!toggleSort}" rerender="pgTable" >
                      <apex:param name="sortField" value="Status" assignTo="{!sortField}"/>
                        <apex:outputPanel rendered="{!BEGINS(sortField,'Status')}">
                          &nbsp;<apex:image value="{!IF(sortDir = 'desc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                        </apex:outputPanel>
                </apex:commandLink>
            </apex:facet>         
            <apex:outputField value="{!tsk.Status}"/>
        </apex:column>
       
        <apex:column headerValue="Assigned To">
            <apex:outputField value="{!tsk.Owner.Name}"/>
        </apex:column>
        
       <apex:column headerValue="Due Date">
          <apex:facet name="header">
                <apex:commandLink value="ActivityDate" action="{!toggleSort}" rerender="pgTable" >
                      <apex:param name="sortField" value="ActivityDate" assignTo="{!sortField}"/>
                        <apex:outputPanel rendered="{!BEGINS(sortField,'ActivityDate')}">
                          &nbsp;<apex:image value="{!IF(sortDir = 'desc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                        </apex:outputPanel>
                </apex:commandLink>
          </apex:facet>     
          <apex:outputField value="{!tsk.ActivityDate}"/>
        </apex:column>   
   </apex:pageBlockTable>
     <apex:pageBlockButtons >
         <apex:commandButton value="Previous" action="{!Previous}" rerender="pgTable,pgBlock"
                                    status="status" disabled="{!DisablePrevious}" />
          <apex:commandButton value="Next" action="{!Next}" reRender="pgTable,pgBlock"
                                  status="status" disabled="{!DisableNext}" />
            <apex:actionStatus id="status" startText="Please Wait..."/>
         </apex:pageBlockButtons>
      </apex:pageBlock>
    </apex:form>
  </apex:page>


      
I'm new to using APEX and would really appreciate your help. I found this bit of code online  I need to write a test class to ensure it has coverage for deployment. Can someone please help me construct a test class, or point me in the right direction?  It describes charts with a combination of Bar and Line charts and with pie chart in one grid.

Thanks, Marc

=== Class ====

public class HighchartsController
{ 
     public String str {
     get {
            String res = '';
            Integer i;
            //SOQL
            res = '[';
            for(i=1;i<13;i++)
            res +=  '' + (i+1) +  ',';
            res += 12;
            res += ']';
            return  res;
            }
        }
    public String bar {
     get {
            String str = '';
            Integer i;
            //SOQL
            str = '[';
            for(i=1;i<13;i++)
            str +=  '' + i + ',';
            str += 12;
            str += ']';
            return  str;
            }
    
        }
      
    public List<Integer> X
   {
    get
    {
       //X= '10';
       X=new List<Integer>();
       String q = 'Select count(Id),StageName from opportunity where StageName IN(\'Closed Won\',\'Closed Lost\') group by StageName';
      AggregateResult[] agr =Database.query(q);
     // X = '\''+ String.valueof(agr[0].get('expr0')) + ',' +String.valueof(agr[1].get('expr0')) + '\'';
      X.add(Integer.valueof(agr[0].get('expr0')));
      X.add(Integer.valueof(agr[1].get('expr0')));
      return X;
    }
   set
   {}
    }
   }

 ==== Page ====


<apex:page controller="HighchartsController">

     <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
     <script src="https://code.highcharts.com/highcharts.js"></script>
     <script src="https://code.highcharts.com/modules/exporting.js"></script>

     <div id="container" style="min-width: 310px; height: 400px; margin:0 auto"></div>

        <script>
            pieOrdinate = {!X};
           // pieOrdinate = ServerStr.split(',');
             $(function () {
             $('#container').highcharts({
             title: {
             text: 'Chart showing opportunities'
        },
        xAxis:{
                categories: ['Jan','Feb','Mar','Apr','May','Jun','July','Aug','Sept','Oct','Nov','Dec']
            },
              labels: {
              items: [{
              html: 'Opportunities',
              style: {
                    left: '50px',
                    top: '18px',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
                }
            }]
        },
        series: [ {
            type: 'column',
            name: 'Indian Railways',
            data: {!str}
            //data:[2,3,4,5,6]
        },
         {
            type: 'spline',
            name: 'Monthly Sales', // Average
           // data: [3, 2.67, 3, 6.33, 3.33],   
           data :{!bar},
            marker: {
                lineWidth: 2,
                lineColor: Highcharts.getOptions().colors[3],
                fillColor: 'white'
            }
        },
        {
            type: 'pie',
            name: 'Total consumption',
            data: [ {
                name: 'Lost',
                //y:23,
                y :parseInt(pieOrdinate[0]),
                sliced:true,
                selected:true,
                color: Highcharts.getOptions().colors[1] // Opp's Lost color
              }, 
               {
                name: 'Won',
                y:parseInt(pieOrdinate[1]),
                color: Highcharts.getOptions().colors[2] // Opp's won color
              }],
               center: [100, 80],
               size: 100,
               showInLegend: false,
               dataLabels:
               {
                 enabled:true
               }
        }]
    });
});
  </script>
</apex:page>



I'm performing Search for OwnerId on Task object . I have a User (i.e. Owner) named "Nisarg" . Hence when i search for "Nisarg" it does not give me anything.

When i Debug this in Comsole , following is what i get.What it does is , it searches for Subject and Status.But the requirement is also to search for OnwerId as well on Task which is not happening .. Please help to make any modifications .

Thanks in advance,
Marc.

USER_DEBUG [131]|DEBUG|Select OwnerId,Subject,Status,ActivityDate from Task where (Subject like '%Nisarg%' OR Status like '%Nisarg%')  Order By Subject limit 3 offset 0





private static string JoinSetIds(Set<Id> objIds)
     {
       if(objIds == null || objIds.size() == 0)
       {
         return '';
       }
      List<string> lIds = new List<string>();
       for(Id pId : objIds)
       {
         lIds.add((string)pId);
       }
       return '(\'' + String.join(lIds, '\',\'' ) + '\')';
    } 

 public void queryTasks(){
        
        String qStr2= searchText;
        Set<Id> ownerIds = new Set<Id>();
        String strnormal = '';
        try{
             mydate = date.parse(qStr2);
        }catch(Exception e)
        { }
        
        String strDate = '';
        String ownerIdsCondition = '';
        if(tasks!=null&&tasks.size()>0)
        {
          for(Task t : tasks)
          {
            if(!ownerIds.contains(t.OwnerId))
              ownerIds.add(t.OwnerId);
          }
          ownerIdsCondition = ' OwnerId IN '+JoinSetIds(ownerIds) + ' and ';
        }
        if(mydate != null) {
         // strnormal = String.valueOf(mydate );
          String[] qstr3 = String.valueOf(mydate).split(' ',2); 
          strDate = ownerIdsCondition+' ActivityDate =  '+ qstr3[0] + ' ';
        }else{
       
           strDate  =  ownerIdsCondition+'(Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\') ' + ' Order By '  + sortField;
        }
           
      String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '+strDate+' limit ' + QueryLimit + ' offset ' + OffsetSize;  
       System.debug(qStr); 
      tasks = Database.query(qStr);         
    
   }

<apex:column headerValue="OwnerId">
            <apex:outputField value="{!tsk.OwnerId}"/>
        </apex:column>



I am new to Salesforce development.

I have read a lot about batch apex & schedule apex, but those information getting only theory knowledge for me.

COULD SOME ONE HELP ME TO LEARN ""batch apex schedule apex"" WITH PRACTICAL(Programatic) KNOWLEDGE.


Thanks in advance.
Hi ,

I'm new to integration . Have referred Salesforce documents but didnt understood much . I do not know where to start , I have a requirement to integrate Salesforce with Amazon S3 . So if anyone can help me with the sample code will be very useful . 

Also nice blogs ,useful links for integrations if given would be great.


Thanks,
Marc.
Hi,

Have a requirement where on clicking a button ( custom buttom )  it will take me to the Contact detail page with auto filled Account Name field.
Please help me . I'm confused and any sample code will work best for me . Thanks .Marc

I'm getting an error and not able to find solution . I'm trying to use best practice of trigger using trigger handler . Following is what I did uptil now . Anyone please help me to structure or help me with modification .Thanks in advance.



===Trigger===

trigger OpportunityTrigger on Opportunity (after update) {
   new OpportunityTriggerHandler().run();
}

=== Trigger Handler class ===
public virtual class TriggerHandler {

  public TriggerHandler() { }
  
  // main method that will be called during execution
  public void run() {

     // dispatch to the correct handler method
      if(Trigger.isAfter && Trigger.isUpdate) {
      this.afterUpdate();
    } 
  }

  // context-specific methods for override
  protected virtual void afterUpdate(){}
  protected virtual void afterDelete(){}
    
  // exception class
  public class TriggerHandlerException extends Exception {}

}

== OpportunityTriggerHancler Class== 

I'm getting error in this class .
public class OpportunityTriggerHandler extends TriggerHandler {

   List<Task> tasks = new List<Task>();
   List<Opportunity> Opps = Trigger.new;
   Map <Id, String> oppsOwner = new Map <Id, String> ();
   
   public OpportunityTriggerHandler() {}
  
   protected override void afterUpdate()
  {
    for (Opportunity opp : trigger.new)
    {
        // Check if the StageName has been changed
        if (opp.StageName != trigger.oldMap.get(opp.Id).StageName)
        {
            // get the owner ID's that have been affected
            oppsOwner.put(opp.ownerId, null);
        }
    }

    // Map the owner ID to it's email address
    for (User owner : [SELECT Id, Email FROM User WHERE Id = :oppsOwner.keySet()])
    {
        oppsOwner.put(owner.Id, owner.Email);
    }
        
  }
   
  }


How do i validate through trigger to see that the account and contact associated with an opportunity are correct ? Thanks in advance . Marc


trigger fieldUpdate on Opportunity (after update) {

   List<Task> tasks = new List<Task>();
   List<Opportunity> Opps = Trigger.new;
   Map <Id, String> oppsOwner = new Map <Id, String> ();
       // Go through every opportunity in the trigger
    for (Opportunity opp : trigger.new)
    {
        // Check if the StageName has been changed
        if (opp.StageName != trigger.oldMap.get(opp.Id).StageName)
        {
            // get the owner ID's that have been affected
            oppsOwner.put(opp.ownerId, null);
        }
    }

    // Map the owner ID to it's email address
    for (User owner : [SELECT Id, Email FROM User WHERE Id = :oppsOwner.keySet()])
    {
        oppsOwner.put(owner.Id, owner.Email);
    }
    
    
   for (Opportunity Opp : Opps)
   {
     if(opp.StageName == 'Closed Won' && trigger.oldMap.get(opp.Id).StageName != opp.StageName) {
     
     Task tsk = new Task(whatID = Opp.ID, Ownerid = Opp.OwnerId);
     tasks.add(tsk); 
    }  
   } 
   insert tasks;
    
 
    List <Messaging.SingleEMailMessage> emails = new List <Messaging.SingleEMailMessage> ();

    // Go again through every opportunity in the trigger
    for (Opportunity opp : trigger.new)
    {  
        // Only work with opportunities that have owners mapped to their email addresses (only those ones have their status changed)
        if (oppsOwner.get(opp.OwnerId) != null)
        {
            // Create an email message and add it to the list
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            List <String> toAddresses = new List <String> {oppsOwner.get(opp.ownerId)};
            // set it in meassage as
            mail.setToAddresses(toAddresses);
            mail.setSubject('Automated Email : Opportunity StageName Updated');
            String body = 'The status has been changed on the opportunity record with StageName ' + opp.StageName;
            mail.setPlainTextBody(body);
            emails.add(mail);
        }
    }
    Messaging.sendEmail(emails);
       
  }


I'm getting an error while displaying Highcharts . The error is : SCRIPT1007: Expected ']' at line 47,character 4. Pressing my head since hours and trying to solve but no luck yet :( .Really appreciate the help.Thanks in advance. Marc


==== Class ===

public class HighChartsController3
{
  public String[] total;
  public String[] gettotal()
  {
     String q = 'SELECT count(Id),Name Total FROM Account group by Name';
     AggregateResult[] agr =Database.query(q);
     String[] strarray = new String[agr.size()];
     for (AggregateResult ar : agr) 
     {
         strarray.add(String.valueof(ar.get('Total')));

     }            

     return strarray ;
   }


public String[] position;
public String[] getposition()
{

     String q = 'SELECT count(Id),Name FROM Opportunity group by Name';
     AggregateResult[] agr =Database.query(q);
     String[] strarray = new String[agr.size()];

      for (AggregateResult ar : agr)
      {
         strarray.add(string.valueOf(ar.get('Name')));
     }

     return strarray ;
     }
   }



    === Page ===

<apex:page controller="HighChartsController3">
  <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" />
  <script src="https://code.highcharts.com/highcharts.js"></script>
  <script src="https://code.highcharts.com/modules/exporting.js"></script>

   <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

  <Script>
    $(function () {
     $('#container').highcharts({
     chart: {
        type: 'column'
    },

    title: {
        text: 'Total # of Apllications vs # of Open Jobs'
    },

    xAxis: {
     categories: {!position}
    // categories: ['abc','parth','hello']        

    },

    yAxis: {
        allowDecimals: false,
        min: 0,
        title: {
            text: 'Number'
        }
    },

    tooltip: {
        formatter: function () {
            return '<b>' + this.x + '</b><br/>' +
                this.series.name + ': ' + this.y + '<br/>' +
                'Total: ' + this.point.stackTotal;
        }
    },

    plotOptions: {
        column: {
            stacking: 'normal'
        }
    },

    series: [{
        name: 'New',
        data: [5, 3, 4, 7, 2],
        stack: 'Application'
    }, {
        name: 'Schedule Interviews',
        data: [3, 4, 4, 2, 5],
        stack: 'Application'
    }, {
        name: 'Hired',
        data: [3, 4, 4, 2, 5],
        stack: 'Application'
    },{
        name: 'Rejected',
        data: [3, 4, 4, 2, 5],
        stack: 'Application'
    },

      {
        name : 'Total Applications',
        data : {!total}           
        //data : [100,200,300],
        stack : 'Total'
        }]
      });
   });

  </script>
</apex:page>


Can i use setOrgWideEmailAddressId(Id) to send the FROM address in my case. My requirement is to send an email FROM Owner to the particular Lead when the Lead Status is changed.

I've enabled Org Wide Addressed in the Org Setup. Please help.

trigger UpdateLeadStatus on Lead (after update) {
    Map <Id, String> leadsOwner = new Map <Id, String> ();

    // Go through every lead in the trigger
    for (Lead lead : trigger.new)
    {
        // Check if the status has been changed
        if (lead.Status != trigger.oldMap.get(lead.Id).Status)
        {
            // get the owner ID's that have been affected
            leadsOwner.put(lead.ownerId, null);
        }
    }

    // Map the owner ID to it's email address
    for (User owner : [SELECT Id, Email FROM User WHERE Id = :leadsOwner.keySet()])
    {
        leadsOwner.put(owner.Id, owner.Email);
    }

    List <Messaging.SingleEMailMessage> emails = new List <Messaging.SingleEMailMessage> ();

    // Go again through every lead in the trigger
    for (Lead lead : trigger.new)
    {  
        // Only work with leads that have owners mapped to their email addresses (only those ones have their status changed)
        if (leadsOwner.get(lead.OwnerId) != null)
        {
            // Create an email message and add it to the list
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            List <String> toAddresses = new List <String> {leadsOwner.get(lead.OwnerId)};
            mail.setToAddresses(toAddresses);
            mail.setSubject('Automated Email : Lead Status Updated');
            String body = 'The status has been changed on the lead record with ID ' + lead.Id;
            mail.setPlainTextBody(body);
            emails.add(mail);
        }
    }
    Messaging.sendEmail(emails);
}


I've written a trigger where a notification in form of an email is sent to the  Owner when the Lead Status field is changed .But the requirement was different and i did it to send email to the Owner which is not.

 A help in Trigger where the requirement is that, an email should be sent from the Owner to the particular Lead Please help me to achieve this..Below is the code.

Really appreciate the help.
trigger UpdateLeadStatus on Lead (after update) {
    Map <Id, String> leadsOwner = new Map <Id, String> ();

    // Go through every lead in the trigger
    for (Lead lead : trigger.new)
    {
        // Check if the status has been changed
        if (lead.Status != trigger.oldMap.get(lead.Id).Status)
        {
            // get the owner ID's that have been affected
            leadsOwner.put(lead.ownerId, null);
        }
    }

    // Map the owner ID to it's email address
    for (User owner : [SELECT Id, Email FROM User WHERE Id = :leadsOwner.keySet()])
    {
        leadsOwner.put(owner.Id, owner.Email);
    }

    List <Messaging.SingleEMailMessage> emails = new List <Messaging.SingleEMailMessage> ();

    // Go again through every lead in the trigger
    for (Lead lead : trigger.new)
    {   
        // Only work with leads that have owners mapped to their email addresses (only those ones have their status changed)
        if (leadsOwner.get(lead.OwnerId) != null)
        {
            // Create an email message and add it to the list
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
            List <String> toAddresses = new List <String> {leadsOwner.get(lead.OwnerId)};
            mail.setToAddresses(toAddresses); 
            mail.setSubject('Automated Email : Lead Status Updated'); 
            String body = 'The status has been changed on the lead record with ID ' + lead.Id; 
            mail.setPlainTextBody(body); 
            emails.add(mail);
        }
    }
    Messaging.sendEmail(emails);
}


Can anyone please help me out to get a tigger . I would like to change Status of a Lead  and notification should be sent from the owner of that lead .

I know notification can be sent using Workflow . But i dont know how to write Trigger.Help appreciated.

Thanks,
Marc
I've an issue while sorting date by arrow sorting. I successfully implemented this for "Subject" and "Status" field on Task object but while i click on Date column , it gives me error saying : unexpected token: <EOF> Error is in expression '{!toggleSort}' in page new_test_task_assignment: Class.PagingTasksController1.toggleSort: line 61, column 1

I've given endless try but still the same . Can anyone please help me to correct my mistake(s) .. Please help .

Thanks in advance.
 Marc   

public class PagingTasksController1{
    
    public List<Task> tasks {get;set;}
    public Task del;
    public Task taskDel;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit =3 ;
    public List<Task> lstTasks {get;set;}
    public String searchText {get;set;}
    public String rowIndex {get;set;}
    public Date mydate;
    public Integer totalCount {get;set;}
    public string sortField = 'Subject';  // default sort column
    private string sApplySOQL = '';
    public List<Task> delattendeeList {get;set;}
    
    public List<Task> delAttendees {get; set;}
    
    public PagingTasksController1(ApexPages.StandardController controller) {
        
        taskDel= (Task)controller.getRecord();
        tasks = [Select id,Subject,Status,ActivityDate,Owner.Name from Task];
        // this.Tasks=Tasks[0];
        totalCount = Tasks.size();
        
        delattendeeList = new List<Task>();
        delattendees = new List<Task>();
    }
    
    
    // the current sort direction. defaults to ascending
    public String sortDir {
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }
    
    // the current field to sort by. defaults to role name
    public String getsortField() {
        return sortField;
    }
    
    // the current field to sort by.
    public void setsortField(string value) {
        sortField = value;
    }
    
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
        
        integer iIndex = sApplySOQL.indexOf('Order By');
        if (iIndex > -1){
            sApplySOQL = sApplySOQL.substringBefore('Order By');
            sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir +  ' limit ' + QueryLimit + ' offset ' + OffsetSize;
        }
        
         System.debug('Before Sorted Date is ' +sApplySOQL);
         tasks = Database.query(sApplySOQL );  // here it where gives me error
         
    }
       
    public PagingTasksController1 (){
        //CountTotalRecords= [select count() from Task];
        //String qStr2= '7/23/2014';
        
    }
    
    /* public List<Task> getTasks(){
    if(tasks == null){
    tasks = new List<Task>();
    }
    return tasks;
    }  */
    
    public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
    
    public void queryTasks(){
        
        String qStr2= searchText;
        String strnormal = '';
        try{
            mydate = date.parse(qStr2);
        }catch(Exception e)
        { }
        
        String strDate = '';
        if(mydate != null) {
            // strnormal = String.valueOf(mydate );
            String[] qstr3 = String.valueOf(mydate).split(' ',2);
            strDate = ' ActivityDate =  '+ qstr3[0] + ' ';
        }else{
            
            strDate  =  '(Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\' OR Owner.Name like \'%' +searchText+ '%\') ' + ' Order By '  + sortField;
        }
        
        String qStr = 'Select Owner.Name,Subject,Status,ActivityDate from Task where '+strDate+' limit ' + QueryLimit + ' offset ' + OffsetSize;
        System.debug(qStr);
        tasks = Database.query(qStr);
        
    }
    
    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
        }
    
    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
        }
    
    public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }
    
    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }
    
    public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
    }
    
    public void deleteRow(){
        delete new Task(Id = rowIndex);
        for (Integer i = 0; i < Tasks.size(); i++) {
            if (Tasks[i].Id == rowIndex) {
                Tasks.remove(i);
                break;
            }
        }
    }
}

====== Page =====

<apex:page controller="PagingTasksController1" docType="html-5.0">
    <apex:form >
     <apex:variable var="rowNumber" value="{!0}"/>
        <apex:pageBlock title="Tasks" id="pgBlock" >
            <apex:pageBlockButtons >
               <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
               <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
            </apex:pageBlockButtons>
        <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                    hideOnEdit="editButton" event="ondblclick"
                    changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/> 
        <apex:inputText id="searchBox" value="{!searchText}"/>
        <apex:commandButton value="Search" reRender="pgTable,pgBlock" action="{!findTasks}"/>
        
        <apex:pageBlockTable value="{!Tasks}" var="tsk" id="pgTable">
           <apex:column headerValue="Action" >
              <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pgTable"> 
                 <apex:param name="rowIndex" value="{!tsk.id}" assignTo="{!rowIndex}" />
              </apex:commandButton>              
           </apex:column> 
           
        <!-- <apex:column headerValue="Action" >
          <apex:outputLink value="{!URLFOR($Action.Task.Delete, .id,['retURL'='/apex/New_Test_task_Assignment'])}"> Delete</apex:outputLink>
        </apex:column>  -->
        <apex:column headerValue="Subject">
            <apex:facet name="header">
                <apex:commandLink value="Subject" action="{!toggleSort}" rerender="pgTable" >
                  <apex:param name="sortField" value="Subject" assignTo="{!sortField}"/>
                    <apex:outputPanel rendered="{!BEGINS(sortField,'Subject')}">
                        &nbsp;<apex:image value="{!IF(sortDir = 'desc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                    </apex:outputPanel>
                </apex:commandLink>
            </apex:facet>     
          <apex:outputField value="{!tsk.Subject}"/>
        </apex:column>
           
        <apex:column headerValue="Status">
            <apex:facet name="header">
                <apex:commandLink value="Status" action="{!toggleSort}" rerender="pgTable" >
                      <apex:param name="sortField" value="Status" assignTo="{!sortField}"/>
                        <apex:outputPanel rendered="{!BEGINS(sortField,'Status')}">
                          &nbsp;<apex:image value="{!IF(sortDir = 'desc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                        </apex:outputPanel>
                </apex:commandLink>
            </apex:facet>         
            <apex:outputField value="{!tsk.Status}"/>
        </apex:column>
       
        <apex:column headerValue="Assigned To">
            <apex:outputField value="{!tsk.Owner.Name}"/>
        </apex:column>
        
       <apex:column headerValue="Due Date">
          <apex:facet name="header">
                <apex:commandLink value="ActivityDate" action="{!toggleSort}" rerender="pgTable" >
                      <apex:param name="sortField" value="ActivityDate" assignTo="{!sortField}"/>
                        <apex:outputPanel rendered="{!BEGINS(sortField,'ActivityDate')}">
                          &nbsp;<apex:image value="{!IF(sortDir = 'desc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                        </apex:outputPanel>
                </apex:commandLink>
          </apex:facet>     
          <apex:outputField value="{!tsk.ActivityDate}"/>
        </apex:column>   
   </apex:pageBlockTable>
     <apex:pageBlockButtons >
         <apex:commandButton value="Previous" action="{!Previous}" rerender="pgTable,pgBlock"
                                    status="status" disabled="{!DisablePrevious}" />
          <apex:commandButton value="Next" action="{!Next}" reRender="pgTable,pgBlock"
                                  status="status" disabled="{!DisableNext}" />
            <apex:actionStatus id="status" startText="Please Wait..."/>
         </apex:pageBlockButtons>
      </apex:pageBlock>
    </apex:form>
  </apex:page>


      
hi all,

i have a functionality wherein the pageblock table data is sorted when an appropriate column header is clicked.
Even though this functionality seems to be working fine,
it takes a lot of time to display the result on the VF page

Can anyone help me to make the records display faster on VF page?

below is my method i.e invoked whenever a column header is clicked

public PageReference doSorting()
    {
        wrapperLst.clear();
        sortOrder= sortOrder.equals('asc') ? 'desc' : 'asc';
        System.debug('***** sort order is'+sortOrder);
        List<Product__c> prodlst=runQuery();
        if(prodlst.isEmpty()==false)
        {
            for(Product__c pnew2: prodlst)
            {
                        OrderWrapper ow2=new OrderWrapper();
                        ow2.prodItem=pnew2;
                        ow2.oliItem=new Order_Line_Item__c();
                        ow2.isChecked=false;
                        wrapperLst.add(ow2);
           }
        }
        return null;
    }
    
    public  List<Product__c> runQuery()
    {
         sortedProds.clear();
         sortedProds=Database.Query('select id,name,Product_Brand__c,Product_Category__c from         Product__c Order by '+sortParam+' '+sortOrder);
         return sortedProds;
    }