function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC@ErrorSFDC@Error 

How to Block existing record

Hi All
Is there any way to block (non editable )all existing record of one custom object after some specific date.
Best Answer chosen by SFDC@Error
Ahmad J. KoubeissyAhmad J. Koubeissy
so the query will become:
qu=[select id,RecordType.id,Customer_Location__c,If_Yes_then_Tax__c,Total_Basic_Price_new__c,Purpose_of_Sales__c,Opportunity_Product_Detail__c,Type_of_Tax_cal__c,Which_Form_Text__c,Declaration_form_be_provided__c, Excise_Duty__c,Created_Date__c from Quote__c where Opportunity_Product_Detail__c in:opppdt and createddate=today];

If this works, kindly set as best answer

All Answers

Ahmad J. KoubeissyAhmad J. Koubeissy
try this trigger 
trigger BlockRecords on object__c (Before Update){
     for(object__c object:trigger.New){
          if(Date.today() > specific_date_field__c){
                 object.addError('You cannot modifiy this record.');
          }
     }
}

Mar as best answer if this solves your needs
SFDC@ErrorSFDC@Error
Hay @ahmad
I have tried to implement this but after that i have got error from another trigger which i have written.i am getting error when i am going to craete record like this 
Review all error messages below to correct your data.
Apex trigger Tax_Calculation caused an unexpected exception, contact your administrator: Tax_Calculation: execution of BeforeInsert caused by: System.DmlException: Update failed. First exception on row 1 with id a0ZO000000KWIXQMA5; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You cannot modifiy this record.: []: Trigger.Tax_Calculation: line 115, column 1
 
trigger Tax_Calculation on Quote__c (after insert,after update)
{

  set<id> opppdt=new set<id>();
  List<Quote__c> upqu=new List<Quote__c>();
  List<Quote__c> upqu1=new List<Quote__c>();
    
  List<Quote__c> qu=new List<Quote__c>();
  List<Quote__c> C1quote=new List<Quote__c>();
  
  if (!FollowUpTaskHelper.hasAlreadyCreatedFollowUpTasks()) 
    {
    
    for(Quote__c q:trigger.new)
    {
    opppdt.add(q.Opportunity_Product_Detail__c);
    }
    qu=[select id,RecordType.id,Customer_Location__c,If_Yes_then_Tax__c,Total_Basic_Price_new__c,
          Purpose_of_Sales__c,Opportunity_Product_Detail__c,Type_of_Tax_cal__c,Which_Form_Text__c,Declaration_form_be_provided__c,
          Excise_Duty__c,Created_Date__c from Quote__c where Opportunity_Product_Detail__c in:opppdt];
    
    system.debug('quote records'+C1quote);
       
    
        id rt1=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C1').getRecordTypeId();
        id rt2=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C2').getRecordTypeId();
        Id rt3=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C3').getRecordTypeId();
        id rt4=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C4').getRecordTypeId();
        id rt5=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C5').getRecordTypeId();
        Id rt6=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C6').getRecordTypeId();
        Id rt7=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C7').getRecordTypeId();
        id rt8=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C8').getRecordTypeId();
        Id rt9=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C9').getRecordTypeId();
        Id rt10=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C10').getRecordTypeId();
        id rt11=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C11').getRecordTypeId();
        id rt12=Schema.SObjectType.Quote__c.getRecordTypeInfosByName().get('C12').getRecordTypeId();
        
 
 //This is new calculation for c1 product(AIDC) only new tax calaculation 
 
            for(Quote__c c1q:qu)
            {
            if(c1q.RecordTypeid==rt1 || c1q.RecordTypeid==rt4 || c1q.RecordTypeid==rt7 || c1q.RecordTypeid==rt8 || c1q.RecordTypeid==rt12)
            {
            if(c1q.Customer_Location__c=='CANADA')
            {
            c1q.If_Yes_then_Tax__c=18;
           
            upqu1.add(c1q);
            }
            }
            }
    
           FollowUpTaskHelper.setAlreadyCreatedFollowUpTasks();
            update upqu1;
            
            
            }
            
          
}
 
trigger BlockRecords on Quote__c (Before Update){
     for(Quote__c Qt:trigger.New){
          if(Date.today() > Qt.Created_Date__c){
                 Qt.addError('You cannot modifiy this record.');
          }
     }
}


 
Ahmad J. KoubeissyAhmad J. Koubeissy
the trigger Tax_Calculation  is updating the quotes returned from the following query:
qu=[select id,RecordType.id,Customer_Location__c,If_Yes_then_Tax__c,Total_Basic_Price_new__c,
Purpose_of_Sales__c,Opportunity_Product_Detail__c,Type_of_Tax_cal__c,Which_Form_Text__c,Declaration_form_be_provided__c, Excise_Duty__c,Created_Date__c from Quote__c where Opportunity_Product_Detail__c in:opppdt];
When updating these quotes the newly created trigger will be fired because some of these quotes have a created date older then today, you have two solution:
- modify the query to select only the quotes created today
- bypass the trigger for the quotes of CANADA.

Tell me what you think
 
SFDC@ErrorSFDC@Error
Need to modify the query to select only the quote created today
Ahmad J. KoubeissyAhmad J. Koubeissy
so the query will become:
qu=[select id,RecordType.id,Customer_Location__c,If_Yes_then_Tax__c,Total_Basic_Price_new__c,Purpose_of_Sales__c,Opportunity_Product_Detail__c,Type_of_Tax_cal__c,Which_Form_Text__c,Declaration_form_be_provided__c, Excise_Duty__c,Created_Date__c from Quote__c where Opportunity_Product_Detail__c in:opppdt and createddate=today];

If this works, kindly set as best answer
This was selected as the best answer
SFDC@ErrorSFDC@Error
Hay is there any way to block clone (means when i clone if record date less than specific date we cant clone )