Monday, 27 October 2014

SOQL query of Knowledge Articles

SOQL query of Knowledge Articles


SELECT ArticleNumber,ArticleType,CreatedById,UrlName,VersionNumber FROM Offer__kav where PublishStatus = 'Online' AND Language ='en_US'


Output:- 


ArticleNumberArticleTypeCreatedByIdUrlNameVersionNumber
1000001008Offer__kav00590000001DZcHAAWMy-first-Article1
2000001004Offer__kav00590000001DZcHAAWHow-can-I-cancel-my-flight1
3000001006Offer__kav00590000001DZcHAAWIs-my-passport-valid1
4000001000Offer__kav00590000001DZcHAAWfirst-offer11
5000001001Offer__kav00590000001DZcHAAWsecond-offer21





SOQL query of Knowledge Articles

Monday, 11 August 2014

Generate report for all test classes In salesforce (SFDC)

 Generate report for all test classes in salesforce (SFDC)

/*
    to meet this requirement i created a scheduler class (TestResultScheduler ), a main class (TestResultGenerator ) , and one future method class (testLog) to retrieve all test class status and email the result.

*/

Thursday, 26 June 2014

Create a report using apex class and send as an Email Attachment

/*
Create a customize report to send specific user via email, using apex class and scheduler in email attachment.

Suppose we have object Job__c and specific user need daily email how much Job everyday created my his team. (here I am defining very simple scenario but it is very useful for complex and complected report)

I am using here single object Job__c and 3 apex classes to meet this requirement.
also i try to cover following scenario

a batch Apex job that contains 20,000 records and is executed without the optional scope parameter is considered five transactions of 200 records each
*/

Tuesday, 6 May 2014

Bob Buzzard Blog: Reading Barcodes in Salesforce1

Bob Buzzard Blog: Reading Barcodes in Salesforce1: A little over a month ago I wrote a post on Reading QR Codes in Salesforce1 . At the time I added an entry to my todo list to investigate ba...

Monday, 5 May 2014

Handle ENTER event key press in visual force page

 Handle ENTER event key press in visual force page OR
 Preventing default form submission and calling an action instead

<apex:page standardController="account" >
       <script type="text/javascript">      
     
   function submitListener(e){
    var keynum = 0;
    if (window.event){
        keynum = window.event.keyCode;
    }
    else if (e.which){
        keynum = e.which;
    }
    // Here we check whether the Enter button was pressed
    if (keynum == 13){
        onFormSubmit();
    }
}

 </script>
<apex:form id="orderSearchForm" onkeyup="submitListener(event)">

<apex:actionFunction name="onFormSubmit"    action="{!save}"  />
        <apex:pageBlock title="View AND Edit">
<apex:pageBlockButtons >   
                        <!--   --> <apex:commandButton action="{!cancel}" value="Cancel"/>   
              <apex:commandButton action="{!save}" value=":-)"  />

              <apex:commandButton action="{!cancel}" value="Cancel"/>
                
</apex:pageBlockButtons>
            
<apex:pageblockSection columns="2">
       <apex:pageblockSection columns="1">
                  Name:  {!account.name}
                </apex:pageblockSection>
                            <apex:pageblockSection columns="1">
                  <apex:inputField value="{!account.name}" />
                  <apex:inputField value="{!account.type}" />
                  <apex:inputField value="{!account.industry}"/>
                  <apex:inputField value="{!account.fax}" />
                </apex:pageblockSection>
            </apex:pageblockSection>            
        </apex:pageBlock>
    </apex:form>
</apex:page>






Wednesday, 30 April 2014

Rendering a page block section based on conditions


set dynamically, Multiple Conditions for Rendered Attribute
set dynamically ,Rendering a page block section based on conditions

/*
   Consider one  custom object:-  A__c

and A__c has fields :-  First_Name__c, Last_Name__c, Age__c and Contact_Details__c

Suppose when user opted First then user can see 4 fields but When user opted Second then user can see only two fields.

*/


/*Code for Visualforce (Vf)  page*/

<apex:page standardController="A__c" extensions="renderedconditionalcntrl"  >

<apex:form >

<apex:pageBlock title="Rederer with condition">

        <apex:outputLabel value="My Options"> </apex:outputLabel>
         <apex:inputField label="My Option" value="{!Aobj.My_Option__c}">
             <apex:actionSupport event="onchange" action="{!changeevent}"  status="displaystatus" immediate="false" reRender="c1"/>            
        </apex:inputField>

<apex:pageBlockSection id="c1" columns="1" collapsible="false">

        <apex:pageBlockSectionitem rendered="{! IF( isFirstDiv || isSecondDiv,true,false)}" >
     
                <apex:outputLabel value="First Name"> </apex:outputLabel>
             <apex:inputField label="First Name" value="{!Aobj.First_Name__c}" />
        </apex:pageBlockSectionitem>
     
        <apex:pageBlockSectionitem rendered="{! IF( isFirstDiv || isSecondDiv,true,false)}" >
                <apex:outputLabel value="Last Name"></apex:outputLabel>
                          <apex:inputField label="Last Name" value="{!Aobj.Last_Name__c}" />
        </apex:pageBlockSectionitem>
     
     
          <apex:pageBlockSectionitem rendered="{!isFirstDiv}" >
                <apex:outputLabel value="Age"></apex:outputLabel>
                        <apex:inputField label="Age" value="{!Aobj.Age__c}"/>
        </apex:pageBlockSectionitem>
     
        <apex:pageBlockSectionitem rendered="{!isFirstDiv}">
                <apex:outputLabel value="Contact Number"></apex:outputLabel>
                          <apex:inputField label="Contact Number" value="{!Aobj.Contact_Details__c}"/>
        </apex:pageBlockSectionitem>

     

                 
 </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

/*Code for Apex class (extensions)*/


public with sharing class renderedconditionalcntrl {

    public boolean isFirstDiv{get;set;} //first flag
    public boolean isSecondDiv{get;set;} //second flag
    public A__c Aobj{get;set;}
    public renderedconditionalcntrl(ApexPages.StandardController controller) {
    
     Aobj = new A__c();
    }
    
    public void changeevent(){
    System.debug('~~~~~~~~~~~~~~~~~~~~~' + Aobj.My_Option__c );
    
    //Set your flag 
    
       isFirstDiv = false;     
       isSecondDiv  = false; 
       
        if(Aobj.My_Option__c  == 'First')
        isFirstDiv = true;
        
         else if(Aobj.My_Option__c  == 'Second'){            
            isSecondDiv  = true;             
        }
        else {
            isFirstDiv = false;
              isSecondDiv  = false;
        }
        
    }

}


Refer following Images for the above implementation :- 


















Tuesday, 18 February 2014

Salesforce: Salesforce - "System mode & User mode" and "With s...

Salesforce: Salesforce - "System mode & User mode" and "With s...: This topic has always been part of discussion where the answer is not satisfactory and convinced to others.  Using this article, I wi...

Tuesday, 4 February 2014

SFDC 401 notes: Get Started for SFDC 401

SFDC 401 notes: Get Started for SFDC 401: 1) For a Contact object, All users should be able to see all the fields except User Y who should net be able to see Mobile No. Field. This ...

Monday, 3 February 2014

Batch Apex in salesforce

/* you need to create a class and to schedule that class write one more class
*/

Class Name:- batchAccountUpdate



global class batchAccountUpdate implements Database.Batchable <sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT Id,Name FROM Account';
        return Database.getQueryLocator(query);
    }
  
    global void execute(Database.BatchableContext BC, List<Account> scope)
    {
         for(Account a : scope)
         {
             a.Name = a.Name + 'L';
             update a;
         }
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}

// to schedule class: - scheduleExpireNotify

global class scheduleExpireNotify implements Schedulable
{
    global void execute(SchedulableContext sc)
    {
        batchAccountUpdate en = new batchAccountUpdate();
        Database.executeBatch(en);
    }
}


Sunday, 2 February 2014

Inline Editing using Visualforce page

<apex:page standardController="Merchandise__c" recordSetVar="acts">
<apex:form >
<apex:pageBlock title="Merchandise">

        <apex:pageblockTable value="{!acts}" var="a">
            <apex:column value="{!a.name}"/>
        </apex:pageblockTable>


// code for inline Editing

 <apex:inlineEditSupport event="ondblclick" showOnEdit="saveButton, cancelButton" hideOnEdit="editButton"/>
 </apex:pageBlock>
</apex:form>
</apex:page>

Wednesday, 29 January 2014

Analytic Snapshot in salesforce


Analytic Snapshot in salesforce

Salesforce Help defines Analytic Snapshots ,it allowed you to load data from a Custom Report to a Custom Object on a regularly scheduled basis
/*
Need to Create Custom object to store data from report,
e.g  create an object AKG__AnalyticalSnapshot__c 
         Create fields on same object to map report fields ,datatype for report field and custom object must be same.
         You can create Analytic Snapshot only for Tabular and Summary type report.
*/
Step 1 :-  Click on Setup ==> Data Management ==>Analytic Snapshots         
    
                         Click on New Analytical Snapshot button 

Step 2 :- Enter all required information 



Step 3:-  Field Mappings



Step 3 :- Schedule Analytic Snapshot 





Tuesday, 28 January 2014

Save point and Rollback in salesforce

/*
   Consider two objects:-  AKG__trans1__c and AKG__trans2__c

and AKG__trans1__c has field :-  Amount  (AKG__tr1Amount__c) field and
AKG__trans2__c has field :-  AKG__tr2Amount__c 

Suppose AKG__tr2Amount__c  is depends on AKG__tr1Amount__c field, and if AKG__tr1Amount__c is null then it will be roll back insert query on AKG__trans1__c.

*/

/*------------------------- VF page Code -------------------------------------*/
<apex:page controller="savepointRollbackCon" tabStyle="Account">
<apex:pageMessages />
<apex:form >
    <apex:pageBlock title="Transaction 1" >
            <apex:pageblockbuttons >
                <apex:commandButton value="SAVE!!" action="{!savemethod}"/>
            </apex:pageblockbuttons>
           
        <apex:pageblocksection title="Insert Trans1">
                <apex:inputField label="Name" value="{!trans1obj.Name}"/>
                <apex:inputField value="{!trans1obj.tr1Amount__c}"/>
           
       
        </apex:pageblocksection>
       
    </apex:pageBlock>
</apex:form>  
</apex:page>

/*-------------------------------controller Code ---------------------------*/

public with sharing class savepointRollbackCon {
     public AKG__trans1__c trans1obj{get;set;}          
     public AKG__trans2__c trans2obj{get;set;}    
                public savepointRollbackCon(){
               
                    trans1obj = new AKG__trans1__c();
                    trans2obj = new AKG__trans2__c();
                }
               
                public void savemethod(){
                //Declare Savepoint
                   Savepoint sp = Database.setSavepoint();
                 insert trans1obj;
             
                try{
         
               
                trans2obj.Name= trans1obj.name;
               
             
                 trans2obj.tr2Amount__c= trans1obj.tr1Amount__c + 20;
               
                 insert trans2obj;
               
               
                }
                catch(Exception e){
                // Use Rollback 
                Database.rollback(sp);
                    ApexPages.addMessage( new ApexPages.message(ApexPages.Severity.Error,' MY ERRRR '+e)) ;
                }
               
                }
}

Thursday, 23 January 2014

Creating Communities using Salesforce

Step 1:-  Enable Communities from (Customize ==> Communities)



 Step 2 :- Select Domain Name


Step 3 :- Select Tabs and pages visible in Community


Step 4 :- Branding is useful for looks and feels for community.


Step 5 :- Login page look


Step 6 :- Email send by from which id.


 Step 7 :- Click on publish button. 


Step 8 :- Activate Contact to User Community 

Step 9 :- Change USER License 

Step 9 :- User Get A welcome mail 

Step 10 :-  Once user click on Activation Link He/ She will redirect on a new page to change password 





Step 11 :- After that User can use community and use chatter feature in it.


Step 12 :- and other user can participate in conversation.


Step 13 :- continue .... in conversations 

Step 15 :- continue .... in conversations 


Wednesday, 22 January 2014

Retrieve data using Workbench or take backup of all meta data,classes ,trigger etc. using Workbench

To retrieve data from salesforce using workbench We need Package.xml. This package must contain all information about backup files.

package must be looks like following way :-


Steps to take backup:-
Step 1 :-  Click on migration and select Retrieve option.



Step 2:- Upload package.xml and click on Next button 





Step 3:- Click on Retrieve button.





Step 4:- Finally you get Download ZIP File.



You can use pacakge.xml file from Eclipse IDE