Monday 16 December 2013

Inline Editing is not available for a specific object

Inline editing is a handy bit of user friendliness,less time consuming and an efficient way of editing a value of a field from the detail page of a record OR from List View of records . Enabling inline editing is simple. We can enable from User Interface settings.
Here an image where you can enable inline editing. 
Go to the Set up-->Customize-->User Interface-- check Enable Inline Editing check box.




Now inline editing concept will not work for some object. Why is it not working for some object ?
To  use inline editing concept then edit action of specific object should not overridden with any visual-force page. If the Edit action has been overridden for an object, Inline Editing will not be available for that object.

To determine this:
For standard objects: Go to Setup | Customize | <Object> | Buttons & Links, and note the "Overridden" checkbox next to the 'Edit' standard button.

For custom objects: Go to Setup | Create | Objects | <Object>, scroll down to the Buttons & links section, and note the "Overridden" checkbox next to the 'Edit' standard button.

Thursday 12 December 2013

How to get Picklist Value of an object Dynamically

This is very simple. I am sharing some code ,please go through this
Here is My Controller 
public class testclass {
    public Job__c job{get;set;}
    public List<SelectOption> options{get;set;}
    public testclass(){
        options = new List<SelectOption>();
        Schema.DescribeFieldResult fieldResult = Job__c.Status__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry f : ple){
       
          options.add(new SelectOption(f.getLabel(), f.getValue()));
        }
    }
   
   
}

My Page 
<apex:page controller="testclass ">
  <apex:form>
      <apex:pageBlock>
          
          Order Status:<apex:selectList id="countries" value="{!job.Status__c}" size="1" required="true" >
              <apex:selectOptions value="{!options}"/>
          </apex:selectList>
      </apex:pageBlock>
      
  </apex:form>
  
</apex:page>

Wednesday 11 December 2013

Sending Custom Object Information in a Mail

Sometimes we try to send some custom object information in mail. For sending mail Sales-force has provided 4 types of email template. We can design the template as per our requirement. We can use simple text template and use merge field to send custom object information. But that template will work perfectly only If we use in the workflow. 
If we send mail from apex code then that merge field value will not be displayed, except we can display Lead ,Contact and User object information.

For example 

Dear {!Contact.Name} -- It will display

Sub-- {!CustomObject.name}-- It will not display.

This functionality is not yet activated by Sales-force, Here is an idea regarding same.

https://success.salesforce.com/ideaView?id=08730000000BpYU

Why not CustomObject information ?

If we use the template in apex code (By using Messaging.SingleEmailmessage method) for sending mail then setTargetObjectId(ID) method is required , Here we can only give id of USER,CONTACT and LEAD.

For example 
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage() ;
mail.setTemplateId(some template id);
mail.setTargetObjectId(ID);
That 's the reason custom object merge field value will not be displayed in mail.

Solutions
Instead using the Sales-force Email template, design an template in apex code (using some HTMLtags depending according to your design).
Just make a query which information you want to send and then pass these value as parameter to a method.
List<CustomObject__c> listofCustomObjects = [SELECT id, Name,.Expiration__c ,Account_Name__c 
                                                                         FROM CustomObject__c]
 for(CustomObject__c license:listofCustomObjects ) {
            
            Integer numberDaysDue = System.Today().daysBetween(license.Expiration__c);
            String name = license.Account_Name__c;
            if(numberDaysDue == 30){
               
                sendingmail(numberDaysDue ,name );
            }  

}

public void sendingmail( Integer noOfdays, String accountName){
         
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage() ;
         String[] toAddresses = new String[] {'jewell@test.com','neha.v@test.com','sexyRadha@test.com'};
         mail.setToAddresses(toAddresses) ;
         mail.setSubject('LMO:'+'  '+accountName+'  '+'licency expiry in'+' '+noOfdays+' '+'days');
        
         String body = '<html lang="ja"><body>'+ 
                          '<br><br>'+'This email alert is to bring to your notice that the licence of the client :'+'  '+'<b>'+accountName+'</b>'+'  '+'is going to expiry within'+'<b>'+' '+noOfdays+' '+'</b>'+
                          '<br><br>'+'From LMO Alert Service'+'</body></html>';
         mail.setHtmlBody(body);
         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        

      }


Friday 6 December 2013

Salesforce Winter 14 – New Features



  • Apex statement  Governor limit is removed
  • Code coverage cloumn is removed in list of apex class
  • OFFSET can be used in SubQuery 
  • New Database methods added Database.getUpdatedDatabase.getDeleted and Database.merge.
  • Preview button added in visual force page
  • New componet  <apex:input> added, type attribute is used in this  <apex:input> component.
  • LoadOnReady=”true”  attribute is added in <apex:includeScript> component .
  • Developer consol support java script css,xml and plain text.
  • Static Resource can be created from Developer consol.
  • Till now Lookup field can only search Name field however now we have option to “search All” Fields.
  • Report chart is added in detail page, maximum 2 chart  can be added.
  • Business process like work flow can be written on User Object.
  • Salesforce login page will be completely customizable.
  • Service Cloud Console” is renamed to “Salesforce Console for Service”.
  • Configuration Only” sandbox renamed to “Developer Pro”.
  • Agent Configuration” renamed to “Live Agent Configuration”







Wednesday 4 December 2013

How to use Date Time Variable in Dynamic Query

In some scenario you might have come across to fetch record with in some date time range. 
Here I am sharing some code for this. Suppose I am querying records from Minutes Object. There is two field Start_Time and End_Time present  in Minutes Object.
This is my page 

 <apex:inputField value="{!minute.Start_Time__c}" required="true" label="From Date"/>
 <apex:inputField value="{!minuteObj.End_Time__c}" required="true" label="To Date"/>
<apex:commandButton action="{!convertValidMinutesToUsage}" value="Process Minute's"/>

This is my controller 
public with sharing class ControllerValidMinutesToUsage {
     public Minute__c minute{get;set;}
     DateTime startDate;
     DateTime endDate;
     string query;

     public ControllerValidMinutesToUsage(){
            minute =  new Minute__c();
    }

    public void convertValidMinutesToUsage(){
       String sStartdate;
       String sEndDate;
       startDate = minute.Start_Time__c;
       sStartdate = startDate.format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');
       endDate = minuteObj.End_Time__c+1;
       sEndDate = endDate.format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');
       query = 'SELECT Start_Time__c ,End_Time__c, Is_Valid__c WHERE Is_Valid__c = false';
       query += ' AND Start_Time__c >='+sStartdate+' '+'AND Start_Time__c <='+sEndDate
       list<Minute__c> =  DateBase.query(query );
    }
}

Tuesday 3 December 2013

How to get key prefix of an Object in Salesforce.

We know there are two types of record-id are present in salesforce.

  • 15 digit -- Case Sensitive
  • 18 digit -- Case Insensitive
Only 3 digit of ids represent object type .


for example 

  • Account-- 001
  • Contact-- 003
  • Opportunities --006
  • Lead  --- 00Q
How will get these prefix dynamically, I mean by using apex code ?

Schema.DescribeSObjectResult r = CustomObject__c.sObjectType.getDescribe();
String keyPrefix = r.getKeyPrefix();
System.debug('Printing --'+keyPrefix );
It will print prefix of Custom Object id.

Monday 2 December 2013

NOT IN Keyword in Soql in Salesforce.

Suppose there is a requirement to fetch all accounts record which don't have any contacts,
how will we do it?

We can fetch account with their corresponding contact record in a in line query.
for example
list<Account> listOfAccounts = [SELECT id, Name,
                                                 (SELECT id,name FROM Contacts)
                                                  FROM Accounts];
list<Account> accountListwithoutContact = new list<Account>();

for(Account act :listOfAccounts ){
      if(act .Contacts !=null && act .Contacts.size() !=0){
              accountListwithoutContact.add(act)   ;
      }

}

accountListwithoutContact list will contain all account which dont have any contacts.

Second approach would be using NOT IN keyword.
list<Account> listOfAccounts = [SELECT id, Name
                                                  FROM Account
                                                  WHERE id NOT IN (SELECT AccountId FROM Contact)];
Now this is the final list which contains all accounts which don't have any contact.

Fetching Unique Record in Salesforce

It seems to be very easy to fetch unique record . You must be thinking Distinct keyword can be used for this. But saleforce does not support Distinct key word.
Another approach is we can us NOT IN key word for this. If we use this some error is there .
list<Account> listofAccounts = [SELECT id, Name 
                          FROM  Account 
                          WHERE Name NOT IN (SELECT Name FROM Account)];

You will face some error;
       COMPILE ERROR: Invalid bind expression type of SOBJECT:Account for column of type String

Because Inner & outer Query should have different object Type. That means if outer query is in Account then inner query must be in Contact.

Then the actual solution is we have to use GROUP BY key word.
GROUP BY returns aggregate result list.
lIST<AggregateResult> listofAccountsAggregateResult = 
                            [SELECT Name
                                                         FROM  Account
                                                         GROUP BY Name];
It will return unique record of Accounts