Monday 1 October 2012

how know String contain only numeric value


A small observation from my side that how know string contain only numeric value.
After some a small fight i got the solution it's very simple. There is many ways to find the solution like use
isNumeric() method etc
The solution which was I got that is Regex yes by Regex  we can know easily  


String x = '123 ';
Pattern numberFormat = Pattern.Compile('[0-9]*');  
Matcher numberMatch = numberFormat.matcher(x);
System.debug('::::::::::::::::::::::::::::::::'+numberMatch.Matches());

It is very simple.

Thanks,

Regards,
Ashlekh Gera.

Saturday 29 September 2012

Getting Picklist Fields From Object and Their Values In Apex


Today i need to finding picklist type fields and their values in my project it's very easy and simple so i want to share my code with you guys. I know some of us know about this but useful for new buddy's 

 // This Map hold all the fields of Opportunity 
 //   { If you want fields of other object replace Opportunity by other object api name}

 Map<String, Schema.SObjectField> M = Schema.SObjectType.Opportunity.fields.getMap();

 //This Map of list hold the picklist fields and picklist values 
 Map<String ,List<Schema.PicklistEntry>> MapofPicklistfieldswithValues 
                                                       = new Map<String ,List<Schema.PicklistEntry>>();

//Now we are itreating field and find that field which is picklist type and keep in our map 
 with their picklist values
  for(Schema.SObjectField x :M.values())
  {
       if(String.valueOf(M.get(String.valueOf(x)).getDescribe().getType())=='PICKLIST')
        {
          //now we find it the field which is picklist type and now we are puting its name and value in Map
           MapofPicklistfieldswithValues.put(String.valueOf(x ),
                                                                   M.get(String.valueOf(x)).getDescribe().getPicklistValues());
         }
  }

  System.debug('Api name of field which are picklist type ::: -'+MapofPicklistfieldswithValues.keyset());

  for(String fieldApiName : MapofPicklistfieldswithValues.keySet())
  {
       for(Schema.PicklistEntry Picklistvalue :MapofPicklistfieldswithValues.get(fieldApiName) )
      {
             System.debug('Name of field:::'+fieldApiName + '_______Picklist values :::'                                         
                                                                                 +Picklistvalue.getValue());
       }
 }

Thanks,

Regards,
Ashlekh Gera.

Wednesday 12 September 2012

Cloud Trivia Winter#13

Hi friends,

This is the all questions which was asked on cloud trivia. This all question are belongs to winter 13 release.
If you want to play cloud trivia and want win prizes then flow @forcedotcom on twitter and  
 to find me @AshlekhGera


 Que 1  What Object type now has dozens of new methods? 
 Ans    String

Que 2   What does the “exec” command do in the Command Line Window of the developer console? 
Ans      Query & Generate log

Que 3  True/False: You can run tests using the Tests tool for any combination of classes you select
            (one, many, all, etc)? 
Ans     True

Que 4  As of #Winter13, there are now HTTP callouts for which two APIs? 
Ans     Callout testing of SOAP and REST services

Que 5 Where can you now load test data from as of #Winter13? 
Ans    load from static resources(CSVs) to test cases

Que 6 Name 2 of the other new tools (besides Perspectives) added to the developer console in #Winter13? 
Ans   #cloudtrivia - Query Editor & Command Line

Que 7 What does “Perspectives” allow you to do in the developer console? 
Ans   When you open a debug log in the Developer Console, it opens in a System Log view which is a collection of panels for analyzing the log. In the Winter ‘13 release, you can create perspectives in a System Log view.

Que 8  What set of tools will be piloted in #Winter13 to allow you to integrate external applications in Salesforce? 
 Ans    Canvas

Que 9: What two formula functions were added for working with the beta Geolocation Custom Field type? 
Ans     DISTANCE and GEOLOCATION

Que 10 Name 5 of the 7 chart types for Visualforce Charting? 
Ans       area, gauge, radar, scatter, bar

Que 11 What prefix should you use to “pass through” attributes in the <apex:outputPanel> component? 
Ans     HTML

Thanks

Wednesday 29 August 2012

Related List on Custom VFP

Hi Friends ,

In this Post you will found how we can show related list on  Custom Visual force Page.

Consider : I have a account record. This account record have many child record on Contact object.
Contact Object have look up of Account.

There is apex code :-

public class CusttomAccount
{
    public Account acc {set;get;}
    public CusttomAccount()
    {
        acc = new Account();
        acc = [select id ,name from Account limit 1];
    }  

}

There is Visual force Page code :- 


<apex:page controller="CusttomAccount" showChat="false" sidebar="false">  
    <apex:pageblock   >
        <apex:pageBlockSection title="Record Detail">
            <apex:pageBlockSectionItem>
             <apex:outputLabel value="Name" />
                <apex:outputLabel value="{!acc.name}" />
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageblock>
    <apex:relatedList subject="{!acc.id}"  list="Contacts" />
    <!-- in list attribute we fill the relationship name and subject we pass the account id whose related list will show -->
    <!--  if your want you show enhancelist please uncomment this code  -->
    <!-- <apex:enhancedList  type="contact" height="300" customizable="false" rowsPerPage="10"  /> -->
</apex:page>



Tuesday 7 August 2012

Operations That Are Available/NotAvailable via Force.com and Metadata API

Hello EveryOne,

In this Post I am telling you about Operations that are available/notAvailable via Force.com and Metadata API .

In my project I want to change api name of all custom fields in my all custom object, Actually I want add a prefix in api name of custom fields. So I took my project into eclipse and change the api name of the field in xml file of every Object.(I thought it would be take less time ) and save it. Then I notice some thing which i am sharing here:

Operations that are available via Force.com and Metadata API
(we can do that things by modifying the xml of object )

   1. Add new fields to an object
    2.Make minor changes such as label, field lengths, etc.
    3.Change the ReferenceTo (eg from Account to Contact) for a field
    4.Changed a field type (eg from currency to number). Logically, some conversions might not be  possible?

Operations that are not available via Force.com and Metadata API(we can't do that things by modifying the xml of object )

    1.Cannot change the API name of an existing field. It will simply create the new field.
    2.Cannot delete existing picklist values
    3.Cannot delete fields
    4.Cannot change some field type (eg tried to change afield from autonumber to text but it didn’t      make the change).

Let me know if it is useful for you.
   
Thanks

Ashlekh Gera.



Sunday 5 August 2012

Salesforce find object from record id and update the record


Hello Friends,

Today i am publish a new post that tell you how to find the object from a record id .
And after find the object we can update the record.
Before update any record we can check, that field exist or not in a object whose value user want to change.
In my example i am changing  the owner id of a record.

idOfRec:   Id of the record whose owner field will be changed.
OwnerId:  Id of the new owner


    //This fucntion is Genric and change the owner of the record
    public static void changeOwner(String idOfRec ,String OwnerId)
    {
        //Hold object name
        String objName ='' ;
     
        //this var indicate that selected object has ownerid field or not
        Boolean isOwner= false;    

        //Hold record of object
        SObject sObjInstance;
     
        //Hold the query string
        String q ='';            
     
        //Hold all objects in schema
        Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
     
        //Hold the object api name
        Set<String> keyPrefixSet = gd.keySet();
     
        //Finding the Object by keyPrefix
        for(String sObj : keyPrefixSet)
        {
            //hold particualr description of a object
            Schema.DescribeSObjectResult r =  gd.get(sObj).getDescribe();
         
            //Hold the keyPrifix of present Objet. This is three digit key
            String tempPrefix = r.getKeyPrefix();
         
            //Compare the keyPrefix of present obj and
            // the record's object which is in argument if match then store
            if(idOfRec.subString(0,3) == tempPrefix)
            {
                Map<String, Schema.SObjectField> FsMap = r.fields.getMap();
            //verifying that object contain the ownerid field or
            //not because child object don't contain this field
                isOwner=FsMap.containsKey('ownerid');
                objName = r.getName();
                break;
             
            }
        }
     
        try
        {
         //if owner id fields exist in the object than update the ownerid and update the record
            if(isOwner)
            {
                //Make a query to get a owner of that record    
                q = 'select id, ownerId from '+ObjName+' where id = \''+idOfRec+'\'';
            //making the instance of that record by fetching data by dynamic query
                sObjInstance= Database.query(q);
             
                //Now put the new user id and update that record
                sObjInstance.put('ownerId',OwnerId);
                update sObjInstance;
            }
            else{
                    ApexPages.addMessage(new ApexPages.message
                                                                          (ApexPages.severity.INFO,'Sorry Owner cann;t be change'));
            }
       }catch(Exception e){}  
    }

Thanks



Sunday 29 July 2012

Date comparison in dynamic query

Hello EveryOne,

This is my first blog and hope this will be help to fresher who are new on salesforce.
Today i learn how fetch the list of record by using of dynamic query with date field camparison.
I got successfully list based on date field criteria.so i am publish this.

Object Api Name  : MyCustomObject__c;
Custom field date type : start_date__c;

List<sObject> myRecords = new List<myObject__c>();

Date dateForCamparsion = System.Today();

String strDate =  String.valueOf(dateForCamparsion );

myRecords =  Database.query ( 'select id ,start_date__c  from MyCustomObject__c
                                                                        where start_date__c ='+strDate );


now  you can check this 

Thank.