Showing posts with label Salesforce. Show all posts
Showing posts with label Salesforce. Show all posts

Thursday, April 10, 2014

Redirect to Custom object home page from visualforce page using Apex

Whenever if you want to redirect to the list view page or the home of the custom object or the standard object from a visualforce page try like this along with pagereference,


Schema.DescribeSObjectResult result = Standard/custom_object__c.SObjectType.getDescribe();
PageReference pg = new PageReference('/'+ result.getKeyPrefix()+'/o');

return pg;

Friday, April 4, 2014

Streaming Realtime data in Visualforce pages - Thanks Sieve

I have been looking so hard to show a real time data into visualforce page quite a long. But after seeing the detailed note by Sieve it turned out to be big pain reliever for me thanks once again to Sieve.

Please have a look at this blog post in Streaming Real Time Data in Visualforce Page and his video session 

Friday, November 8, 2013

Table Using JSON in Salesforce

Send the list data to the page from a controller using JSON.Serialize() function and using the following script traverse through the JSON string display in using a table.

Demo Here 

$(document).ready(function(){

     $("#userdata tbody").html(""); 
   
        var json = {!jsonString};        
        var tr;
        for (var i = 0; i < json.length; i++) {
                        
            var tblRow =
                        "<tr>"
                        +"<td>"+json[i].Accountid+"</td>"
                        +"<td>"+json[i].AccountData+"</td>"                        
                        +"</tr>";
            $(tblRow).appendTo("#userdata tbody");
        }
});

The Page:


 <apex:pageBlock title="Table Using JSON" id="TableUsingJSon">
                <apex:pageBlockSection columns="2">               
                    <apex:outputPanel >
                         <center>
                            <table id="userdata" border="1">
                                <thead>
                                    <th>Account id</th>
                                    <th>Account Name</th>
                                </thead>
                                <tbody></tbody>
                            </table>    
                         </center>    
                    </apex:outputPanel>
                           
                    <apex:pageBlockSectionItem >
                        <apex:outputPanel >
                           {!jsonString} 
                        </apex:outputPanel>
                    </apex:pageBlockSectionItem>
                </apex:pageBlockSection> 
            </apex:pageBlock>

Filter for pageblocktable in salesforce

Often when we create a pageblock table in a visualforce page we wish to filter the records if it is having many records.To filter such a pageblock table we normally use one picklist field or selectlist field and filter the records by passing the selected values to the controller to query the records.

But we can also do this simply by writing a jQuery function.please follow below steps

1)Create a picklist/select list first

2)Write a jQuery function so as to compare the selected value from the picklist and the table values.

3)This can be done by defining a id for the column header in the pageblocktable and in the jQuery funtion traverse through the child elements. Compare both values.

4)If the values are same display the Parent i.e. The current ro else hide.by defining the css display property.
Thus pageblock table can be filtered out very quickly.

JQuery Function:

 $("[id$='AccountFilter']").change(function() {
    var selval=$(this).val();
    $("[id$='AccNameHeader']").each(function(){
          var t= $(this).children('span').text();
           if(selval != 'All'){
             if(selval == t){
                    $(this).parent().css('display','');
             }else{
                    $(this).parent().css('display','none');
             }
           }else{
                $(this).parent().css('display','');
           }                    
        }); 
    });


Visualforce page:

<apex:pageBlock title="JQuery Filter For PageblockTable" id="AccountNamewithFilter">
     <apex:form >
        <apex:selectList value="{!AccPick}" size="1" id="AccountFilter">
             <apex:selectOptions value="{!AccNames}"/>                        
        </apex:selectList>
     </apex:form>
     <apex:pageBlockTable value="{!AccountList}" var="a">
        <apex:column headerValue="Account Name" id="AccNameHeader">
             <apex:outputText styleClass="AccountNameClass" value="{!a.Name}" id="AccName"/>         </apex:column>
        <apex:column headerValue="Phone">
             <apex:outputText styleClass="AccountNameClass" value="{!a.Phone}"/>            
        </apex:column>        
     </apex:pageBlockTable>
</apex:pageBlock>


please check out the live action in my Demo page here.
Pros:
  1. Filtered very quickly.
  2. No need to Query the DB each time.


Cons:
  1. Real time data wont be returned.for this we can keep a refresh button to refresh the page.

Friday, September 21, 2012

Removing the last character from a String - Salesforce

Its easy to remove the last character from a string by using the Substring() method..
If X is a string  the last value can be removed by

                             String Y = X.Substring(0,X.length()-1);

Tuesday, September 18, 2012

EMAIL SERVICES IN SALESFORCE-EXAMPLE

I shared about the Salesforce's Email Services in my previous post..Creating Record by sending email to Salesforce - Part 1..

With this Email Service our part is to create an Apex Class to fetch the details from the email which we sent to Salesforce.

To fetch the data from incoming email we should make use of the Inbound Email messaging feature.

For Example:


global class recordfromEmail implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

Oppotunity Oppty = New Oppotunity();

       String[] emailBody = email.plainTextBody.Split('\n',0); 
       
       oppty.Name = emailBody[0]; 
      
       oppty.Stage = emailBody[1]; 

       insert oppty;

  return Result;
 }

}

EMAIL SERVICES IN SALESFORCE


Yes , it is possible to create a record  just by sending an email to your Salesforce login.....

All can be done with the Salesforce's awesome feature called 'Email Services'.

With This Email Services in Salesforce all we have to do is,

  • Associate one Email id with Salesforce.
  • An Email from Salesforce will be generated and should be associated for.Sending mails to the salesforce.

Email Services can be created by

SetUp --- Develop --- Email Services



The generated email from Salesforce will be like

testemail@9q9zr6cc1w67kjgunhpqftj32.in.sandbox.salesforce.com


Email Service also facilitate users to get known to the errors occurring  while processing the email.

Users can specify an alternate email address to which the errors can be diverted..

Users need to write an Apex class to fetch the details in the email with the help of inBound email Class function.


That's it we can create a Email Service.......

Friday, August 31, 2012

Only Aggregate Expressions use field aliasing Error in Salesforce

Today I came occurs this funky error "Only Aggregate Expressions use field aliasing",,,,,,

Everthing in my trigger are fine but I m not able find where I am wrong.....

For the last go I checked my code from top to bottom, then only I found where I went wrong......

Actually I forget to put a comma in my SOQL Query, like

QueryList = Select a.Id, a.Name , a.phone a.email from account a;

The error got resolved once I corrected my silly mistake......

Cheerssssss