Converting a lookup relationship into master detail using trigger and validation

What we need for this:
 
  Assume object A__c is Master  and object B__c is Detail and A__c is a lookup field on object B__c

  1. To make  the field A__c required we need to write validation on object B and also need to  make it require from page layout
  2. we need to write a written on object A__c that will perform two operation
    1. once object A__c record gets delated all its child records(B__c) need to get deleted
    2. once object A__c record gets undeleted all its child records(B__c) need to get undeleted
  3. if  we are using Rollup summury fields on object A__c we need write a rollup summury trigger on object B__c
  4. Also we need to write criteria if require in trigger B__c to update the parent A__c record field


Code:
  1. Required field Validation
    1.  ISNULL( A__c )

getObjectType by recordId or Prefix

  public static String objectType(String recordIdOrPrefix){
        String objectName = '';
        String IdPrefix = String.valueOf(recordIdOrPrefix).substring(0,3);
             
            //Get schema information
            Map<String, Schema.SObjectType> gd =  Schema.getGlobalDescribe(); 
             
            //Loop through all the sObject types returned by Schema
            for(Schema.SObjectType stype : gd.values())
            {
                Schema.DescribeSObjectResult r = stype.getDescribe();
                String prefix = r.getKeyPrefix();
               if(prefix!=null && prefix.equals(IdPrefix ))
               {
                    objectName = r.getName();
                    break;
                }
            }
        return objectName;
    }

Manipulating Records Field Data Format on standard detail page

Use Formula fields to show fields data in respective format on Salesforce standard detail page like:

  1. Removing '-' from phone field
    1. create a formula fields for that and remove standard phone field from layout

Counters