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 oAKG__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






Monday 20 January 2014

Display Account information with similar Industry

/*
*/
<apex:page controller="vf10controller">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockButtons >
        <apex:commandButton value="Customer Direct Account" action="{!direct}"/>
        <apex:commandButton value="Customer - Channel Account" action="{!channel}"/>      
        </apex:pageBlockButtons>
        <apex:pageblocksection title="My account" >
            <apex:pageblocktable value="{!acts}" var="row"  >
            <apex:column >
            <apex:commandLink value="{!row.name}" action="{!racts1}" rerender="abc">
                <apex:param value="{!row.id}" name="aid"/>
                <apex:param value="{!row.name}" name="aname"/>    
                 <apex:param value="{!row.industry}" name="aindustry"/>              
             </apex:commandLink>
            </apex:column>
           
              <apex:column value="{!row.type}"/>
               <apex:column value="{!row.industry}"/>
            </apex:pageblocktable>
        </apex:pageblocksection>
     

           <apex:pageblocksection title="{!$CurrentPage.parameters.aname}" id="abc">
               <apex:detail subject="{!$CurrentPage.parameters.aid}"/>
                <apex:pageblocktable value="{!racts}" var="row"  >
             
              <apex:column value="{!row.Name}"/>
              <apex:column value="{!row.type}"/>            
               <apex:column value="{!row.industry}"/>
                </apex:pageblocktable>              
         
           </apex:pageblocksection>
     
    </apex:pageBlock>
</apex:form>
</apex:page>
-----------------------------
public class vf10controller {

    List<Account> r_acts;
   // string  type;
    List<Account> acts =  [SELECT name,type,industry,phone,ownerid FROM Account ];          
 
    public List<Account> getacts(){
            return acts;
    }
     public List<Account> getracts(){
            return r_acts ;
    }
 
    public PageReference direct(){
        //type = 'Customer - Direct';
            acts =  [SELECT name,type,industry,phone,ownerid FROM Account WHERE Type ='Customer - Direct'];
         
        return null;
    }
    public PageReference channel(){
      // type = 'Customer - Channel';
             acts =  [SELECT name,type,industry,phone,ownerid FROM Account WHERE Type = 'Customer - Channel'];      
                return null;
    }
 
    public pagereference racts1(){
    r_acts =[SELECT  name,type,industry,phone,ownerid FROM Account WHERE Industry =: ApexPages.CurrentPage().getParameters().get('aindustry') ];
    return null;
    }
}
--------------------


display detail using visualforce page and Ajax

<apex:page standardController="Account" recordSetVar="acts" sidebar="false">

<apex:form id="form">
<apex:pageBlock title="Account info">
 <apex:pageblockSection columns="2">
    <apex:pageblocktable value="{!acts}" var="a">
        <apex:column >
            <apex:commandLink value="{!a.name}" rerender="abc" >
                <apex:param name="aid" value="{!a.id}"   />
                <apex:param name="aname" value="{!a.name}"   />              
            </apex:commandLink>
        </apex:column>
       
        <apex:column value="{!a.type}"/>
           
    </apex:pageblocktable>
   
     <apex:pageblockSection id="abc" title="{!$CurrentPage.parameters.aname}">
    <apex:detail subject="{!$CurrentPage.parameters.aid}" relatedList="false"/>
    </apex:pageblockSection>
   
   
     </apex:pageblockSection>
   
</apex:pageBlock>

 </apex:form>
</apex:page>

Use Tab in Visualforce page :Salesforce

/*
 pass account id in url e.g. https://c.ap1.visual.force.com/apex/vf4?id=0019000000lw1tK
*/

<apex:page standardController="account">
    <apex:pageBlock title="{!account.Name}">
        <apex:tabPanel id="tabpanel">
            <apex:tab Label="Details" reRender="tabpanel" switchType="ajax">
                    <apex:detail relatedList="false"/>
            </apex:tab>
             <apex:tab Label="Contact" reRender="tabpanel" switchType="ajax">
                    <apex:relatedList list="Contacts"/>/>
            </apex:tab>
           
            <apex:tab label="opportunities" reRender="tabpanel" switchType="ajax"  >
            <apex:detail relatedList="false"/>
           
            </apex:tab>
           
           
            <apex:tab label="cases" reRender="tabpanel" switchType="ajax">
            <apex:detail relatedList="false"/>
           
            </apex:tab>
        </apex:tabPanel>
    </apex:pageBlock>
</apex:page>

Friday 17 January 2014

Insert in custom object using VF page and custom controller and use trigger with class

/*
     Insert values on an Custom Object using VF page and custom controller as well as on basis of this use a trigger to insert value in another Custom object  using a trigger and a class.
*/
/*
Consideration following for below code :-
your object names :- AKG__A__c,  AKG__B__c
VF page name:- t1ONACon , controller name :- t1ONACu
Apex Trigger name :- InsertOnB , Apex Class :- trgInsobjB

*/
VF page name:- t1ONACon
<apex:page controller="t1ONACu" >

<apex:pageMessages />
<apex:form >
        <apex:outputLabel value="Saved Successfully!"  style="font-weight:bold;color:green" rendered="{!errFlag}"/>
 <apex:pageBlock title="Insert object A">

     <apex:pageblockButtons >
         <apex:commandButton value="Save!!" action="{!savemethod}"/>
     </apex:pageblockButtons>
  <apex:pageblocksection title="Basic Information">
      <apex:inputField value="{!Aobjstr.name}"/>
     <apex:inputField value="{!Aobjstr.aaa__c}"/>
  </apex:pageblocksection>
 </apex:pageBlock>
</apex:form> 
</apex:page>
 Controller name :- t1ONACu
public with sharing class t1ONACu {

public AKG__A__c Aobjstr {get;set;}
public boolean errFlag{get;set;}

public t1ONACu(){
 Aobjstr= new  AKG__A__c();
 errFlag = false;
}
public void savemethod(){
 
  try{
   insert Aobjstr;
   errFlag = true;
   
   }
   catch(Exception e){
   errFlag = false;  
   ApexPages.addMessage( new ApexPages.message(ApexPages.Severity.Error,'MY ERRRR'+e)) ;
   
   
   }


}

}

Apex Trigger name :- InsertOnB 

trigger InsertOnB on A__c (After insert) {

set<id> objAId = new set<id>();

if(trigger.isinsert){
    for(A__c a:Trigger.new){
    
        system.debug('~~~~~~a'+a);
        objAId.add(a.id); 
    }
        system.debug('~~~~~~objAId'+objAId);
       
        trgInsobjB clsB = new trgInsobjB();
        clsB.insertObjB(objAId,Trigger.new);
}

}

 Apex Class :- trgInsobjB 

public with sharing class trgInsobjB{

    public void insertObjB(set<id> aid,A__c[] Alist ){

    Id myid= new List<id>(aid)[0];
    System.debug('~~~~~~InSide Class aid '+aid+' ~~~~~ Alist '+Alist+'~~~~myid '+myid);
        
        if(aid != null)
        {
            AKG__B__c B = new AKG__B__c();
            B.name = Alist[0].Name+ 'FRM A';
           B.AKG__B_A__c  = myid;
           B.AKG__OnB__c = myid;
    insert B;            
        }

    }
}


Friday 10 January 2014

custom dependent picklist in visualforce

VF page CODE :-
<apex:page controller="custcon" tabStyle="Account" >
    <apex:form >


<apex:selectList required="true" multiselect="false" size="1" label="Type"  value="{!selectedValue}" >
<apex:selectOptions value="{!P1}"/>
<apex:actionSupport event="onchange" reRender="a"/>
</apex:selectList>


<apex:selectList required="true" multiselect="false" size="1" label="Type"   id="a">
<apex:selectOptions value="{!P2}"/>

</apex:selectList>      
       
      
       
    </apex:form>
</apex:page>
--------------------------------controller code
public with sharing class custcon {

public String selectedValue{get;set;}

public String selectedP2{get;set;}
public Boolean ShowP2;

    public custcon(){
       System.debug('~~~~~~~~~~~~selectedValue in controller~~~~~~~~~~~~~~~~ '+selectedValue);
    }
   
//get first picklist value
public List<SelectOption> getP1(){
System.debug('~~~~~~~~~~~~selectedValue in getP1~~~~~~~~~~~~~~~~ '+selectedValue);
List<SelectOption> options = new List<SelectOption>();

options.add( new SelectOption('None','--None--'));
options.add(new SelectOption('A','A'));
options.add( new SelectOption('B','B'));
return options;


}

public void setP1(String s){
    this.selectedValue = s;
    System.debug('~~~~~~~~~~~~setP1~~~~~~~~~~~~~~~~ '+s);
     System.debug('~~~~~~~~~~~~selectedValue in setP1~~~~~~~~~~~~~~~~ '+selectedValue);
   // this.ShowP2= true;
}

//Child Picklist Value

public List<SelectOption> getP2(){
System.debug('~~~~~~~~~~~~GETP2~~~~~~~~~~~~~~~~ '+selectedValue);
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('None','--None--'));

    if(selectedValue == 'A') {
    options.add(new SelectOption('aa','aa'));
    options.add(new SelectOption('aaa','aaa'));
    }
else
    if(selectedValue == 'B'){
    options.add(new SelectOption('bb','bb'));
    options.add(new SelectOption('bbb','bbb'));
    }
return options;

}
public void setP2(String s){
    this.selectedP2 =s;
   // this.ShowP2= true;
}

}