• santhosh konathala 17
  • NEWBIE
  • 210 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 29
    Questions
  • 45
    Replies
vf page:

<apex:page controller="AccountDelete" >
<apex:form >
<apex:outputlabel value="RecordToDelete "/>
  
<apex:inputText value="{!RecordToDelete}" label="RecordToDelete"/> <br/><br/>
<apex:outputlabel value="phone"/>
<apex:inputText label="phone"/><br/><br/>
<apex:commandButton value="Delete" action="{!DeleteName}"/>
<apex:param name="AccountDelete" value="abc" assignTo="{!RecordToDelete}"/>


</apex:form>

</apex:page>

Controller:

Public with sharing class AccountDelete{

Public Id RecordToDelete{get;set;}

Public List<account> acclist {get;set;}

public void DeleteName()
{
 acclist=Database.query('Select id from account where id=:'+ RecordToDelete);
system.debug('Record id to delete ='+ RecordToDelete);
if(acclist.size()>0 & acclist !=null)
{
delete acclist;
}
}
}

 

Public with sharing class MTX_SupplierDelete
{

    public Integer NoOfDays { get; set; }

public List<MTX_SupplierOracleAP__c> supplierList {get; set;}


public void DeleteSupplier()
   {
     Date dt = Date.today() - NoOfDays ;
     supplierList = Database.query('Select id from MTX_SupplierOracleAP__c where ProcessDate__c <=:dt');
     system.debug('Records fetched by given date'+ dt);
     
     system.debug('Fetched records size is'+ supplierList.size());
     system.debug('Supplier records fetched'+ supplierList);
     delete supplierList;

   }   

}
global class TechMDeletion implements Database.Batchable<sObject>
{   
    
    
  
    global Database.QueryLocator start(Database.BatchableContext bc)
    {
        date d=system.today().adddays(-30);        
        return Database.getQueryLocator([Select id from TechM__c where CreatedDate =:d]);


  
    } 
    
    
    
    global void execute(Database.BatchableContext BC, list<sObject> scope)
    {     
    system.debug('records fetched are'+scope);
        
 
        
            delete scope;   
            DataBase.emptyRecycleBin(scope); 
    }
    
    
    global void finish(Database.BatchableContext BC) 
    {                 
        
        
       
    }
}
public with sharing class MTX_SupplierFromOracleAP{
   
    List<MTX_SupplierOracleAP__c> suppliersWithStatus = new List<MTX_SupplierOracleAP__c>();
    
    public void insertSupplier(){
        
        List<MTX_SupplierOracleAP__c> oracleAPSuppliers = new List<MTX_SupplierOracleAP__c>();
               
        oracleAPSuppliers = [Select Id , NewGSLNumber__c , SupplierNumber__c , SupplierSiteName__c , EntityNumber__c , NSFECapexSupplier__c ,
                                    ActivatedDate__c , DeactivatedDate__c , Status__c , SupplierName__c , 
                                    SupplierAddress__c , SupplierCity__c , SupplierCountry__c ,
                                    SupplierTelephoneNumber__c , SupplierFaxNumber__c , NewSiteName__c , CurrencyIsoCode , SupplierEmail__c ,
                                    VatRegistrationNumber__c  , RemitContLastName__c , RemitContFirstName__c ,
                                    RemittanceFaxNr__c , RemittanceEmail__c , RemittanceTelephoneNr__c ,  SupplierZipCode__c
                              From MTX_SupplierOracleAP__c ];   
        
        Set<String> GSLNumbers = new Set<String>();  
        Set<String> SupplierNumbers = new Set<String>();  
        Set<String> SupplierSiteNames = new Set<String>();
        Set<String> EntityNumbers = new Set<String>();
        Set<String> NSFECapexSuppliers = new Set<String>();
        Set<String> uniqueSuppliers = new Set<String>();
        for(MTX_SupplierOracleAP__c oracleAPSupplier : oracleAPSuppliers){
        
            if(oracleAPSupplier.NewGSLNumber__c != null && oracleAPSupplier.NewGSLNumber__c != ''){
                GSLNumbers.add(oracleAPSupplier.NewGSLNumber__c);
            } 
            SupplierNumbers.add(oracleAPSupplier.SupplierNumber__c);
            SupplierSiteNames.add(oracleAPSupplier.SupplierSiteName__c);
            EntityNumbers.add(oracleAPSupplier.EntityNumber__c);
            NSFECapexSuppliers.add(oracleAPSupplier.NSFECapexSupplier__c);
            String uniqueSupplier = '';
            uniqueSupplier = oracleAPSupplier.SupplierNumber__c +'-'+ oracleAPSupplier.SupplierSiteName__c +'-'+ oracleAPSupplier.EntityNumber__c+'-'+ oracleAPSupplier.NSFECapexSupplier__c ;
            uniqueSuppliers.add(uniqueSupplier);
           
        }
        
        Set<String> existingGSLNumbers = new Set<String>();
        for(Account acc : [Select GSLNumber__c  from Account Where GSLNumber__c IN :GSLNumbers AND BranchCode__c != 'T01' ] ){       
            existingGSLNumbers.add(acc.GSLNumber__c);
        }
        
        Set<String> existingUniqueSuppliers = new Set<String>();
        for(Account acc : [Select Id  , AccountNumber ,SiteName__c , Company_Reg_Number__c , SupplierCategory__c  
                           From Account 
                           Where AccountNumber IN :SupplierNumbers AND
                                 SiteName__c   IN :SupplierSiteNames AND
                                 Company_Reg_Number__c IN : EntityNumbers AND
                                 SupplierCategory__c IN :NSFECapexSuppliers AND
                                 BranchCode__c != 'T01' ] ){       
            String uniqueSupplier = '';
            uniqueSupplier = acc.AccountNumber  +'-'+ acc.SiteName__c +'-'+ acc.Company_Reg_Number__c +'-'+ acc.SupplierCategory__c ;
            existingUniqueSuppliers.add(uniqueSupplier);
        }
        
        
        List<MTX_SupplierOracleAP__c> validSuppliers = new List<MTX_SupplierOracleAP__c>();
        List<MTX_SupplierOracleAP__c> invalidSuppliers = new List<MTX_SupplierOracleAP__c>();
        
        for(MTX_SupplierOracleAP__c oracleAPSupplier : oracleAPSuppliers){
            
            String errorString = '' ; 
             
            if(oracleAPSupplier.NewGSLNumber__c == null || oracleAPSupplier.NewGSLNumber__c == '' ){
                errorString += 'No GSL Number ,' ;
            }
            else if ( existingGSLNumbers.contains(oracleAPSupplier.NewGSLNumber__c)){    
                errorString += 'GSL Number is not unique ,' ;  
            }
            
            String uniqueSupplier = '';
            uniqueSupplier = oracleAPSupplier.SupplierNumber__c +'-'+ oracleAPSupplier.SupplierSiteName__c +'-'+ oracleAPSupplier.EntityNumber__c+'-'+ oracleAPSupplier.NSFECapexSupplier__c ;
            if(existingUniqueSuppliers.contains(uniqueSupplier)){
                 errorString += 'Supplier has not unique combination ,' ;  
            }
            
            if( oracleAPSupplier.ActivatedDate__c != null && oracleAPSupplier.DeactivatedDate__c != null 
                  && oracleAPSupplier.DeactivatedDate__c < oracleAPSupplier.ActivatedDate__c ){
                errorString += 'Deactivated date should be greater than activated date ,' ; 
            } 
            
            oracleAPSupplier.Status__c = '' ; 
            if( oracleAPSupplier.DeactivatedDate__c != null ){
                oracleAPSupplier.Status__c = 'void' ;        
            }   
            /*
            if(oracleAPSupplier.SupplierCategory__c != 'NSFE'){
                errorString += 'Supplier Category is not NSFE ,' ;            
            }
            */
            if(oracleAPSupplier.SupplierName__c == null || oracleAPSupplier.SupplierName__c == ''){
                errorString += 'No Supplier Name ,' ;           
            }  
            
            /*
            if(oracleAPSupplier.EntityName__c == null){
                errorString += 'No Entity Name ,' ;            
            }
            */
            
            /*
            if(oracleAPSupplier.Currency__c == null){
                errorString += 'No Currency ,' ;            
            }
            */
            
            if(oracleAPSupplier.SupplierAddress__c == null || oracleAPSupplier.SupplierAddress__c == ''){
                errorString += 'No Address ,' ;           
            }  
            
            if(oracleAPSupplier.SupplierCity__c == null || oracleAPSupplier.SupplierCity__c == ''){
                errorString += 'No City ,' ;           
            } 
            
            if(oracleAPSupplier.SupplierCountry__c == null || oracleAPSupplier.SupplierCountry__c == ''){
                errorString += 'No Country ,' ;           
            }  
            
            String errorDescription ;
            if(errorString != ''){
                errorDescription = 'Not inserted with listed reason -- '+ errorString.removeEnd(',');
                system.debug('-->Error'+errorDescription);
            }
            
            
            if(errorString == ''){
                validSuppliers.add(oracleAPSupplier);                
            }
            else{
                oracleAPSupplier.ProcessDate__c = system.now();
                oracleAPSupplier.ProcessStatus__c = 'Error' ;
                oracleAPSupplier.ErrorDescription__c = errorDescription  ;
                invalidSuppliers.add(oracleAPSupplier);
            }
            
                     
        }
       
        
       system.debug('-->Valid Suppliers'+validSuppliers);
       system.debug('-->inValid Suppliers'+invalidSuppliers);
   
       suppliersWithStatus.addAll(invalidSuppliers);
       insertValidSuppliers(validSuppliers);
       
       update suppliersWithStatus ;
        
    }   
    
    private void insertValidSuppliers(List<MTX_SupplierOracleAP__c> validSuppliers ){
    
         List<String> supplierIds = new List<String>();
         List<Account> supplierAccounts = new List<Account>();
         Map<String , Contact> supplierContacts = new Map<String ,Contact>();
         List<MTX_Address__c> supplierAddresses = new List<MTX_Address__c>();
         
         for(MTX_SupplierOracleAP__c oracleAPSupplier : validSuppliers){
             
             supplierIds.add(oracleAPSupplier.Id);
             
             Account acc = new Account();
             acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Supplier').RecordTypeId;
             acc.Name = 'test oracle AP interface' ;
             acc.AccountNumber = oracleAPSupplier.SupplierNumber__c ;
             acc.GSLSiteNumber__c = oracleAPSupplier.SupplierSiteNumber__c ;
             acc.SiteName__c = oracleAPSupplier.SupplierSiteName__c ;
             acc.Company_Reg_Number__c = oracleAPSupplier.EntityNumber__c ;
             //acc.CreatedDate = oracleAPSupplier.ActivatedDate__c ;
             //acc.SupplierStatus__c = oracleAPSupplier.DeactivatedDate__c ;
             acc.SupplierStatus__c = oracleAPSupplier.Status__c ;
             acc.Phone = oracleAPSupplier.SupplierTelephoneNumber__c;
             acc.Fax = oracleAPSupplier.SupplierFaxNumber__c ;
             acc.SupplierName__c = oracleAPSupplier.SupplierName__c ;
             acc.GSLNumber__c = oracleAPSupplier.NewGSLNumber__c ;
             acc.SiteName__c = oracleAPSupplier.NewSiteName__c ;
             //acc.SupplierPaymentType__c = oracleAPSupplier.PaymentTerms__c ;
             acc.Currency__c = oracleAPSupplier.CurrencyIsoCode ;
             acc.Email__c = oracleAPSupplier.SupplierEmail__c;
             //acc.VAT_Number__c = oracleAPSupplier.VatRegistrationNumber__c ;   //FIELD_CUSTOM_VALIDATION_EXCEPTION, VAT Number is not required if Country is BLANK: [VAT_Number__c]
             //acc.SupplierCategory__c = oracleAPSupplier.NSFECapexSupplier__c ; Bad picklist value error
             
             supplierAccounts.add(acc);
             
             
             Contact con = new Contact();
             //con.AccountId = acc.Id ;
             con.LastName = oracleAPSupplier.RemitContLastName__c ;
             con.FirstName= oracleAPSupplier.RemitContFirstName__c ;
             con.Fax = oracleAPSupplier.RemittanceFaxNr__c ;
             con.Email = oracleAPSupplier.RemittanceEmail__c ;
             con.Phone = oracleAPSupplier.RemittanceTelephoneNr__c ;
             //con.Mobile = oracleAPSupplier.SupplierMobileNr__c ;
             //con.Name = oracleAPSupplier.SupplierContact__c;
             supplierContacts.put(oracleAPSupplier.Id , con);
            
             
             MTX_Address__c address = new MTX_Address__c();
             address.AddressLine1__c = oracleAPSupplier.SupplierAddress__c;
             address.City__c = oracleAPSupplier.SupplierCity__c ;
             address.PostCode__c = oracleAPSupplier.SupplierZipCode__c ;
             address.Country__c = oracleAPSupplier.SupplierCountry__c ; 
             supplierAddresses.add(address);
            
                   
         }
         
          system.debug('account size is-->'+supplierAccounts.size());
          system.debug('contact size is-->'+supplierContacts.size());
          system.debug('address size is-->'+supplierAddresses.size());
          
          
          Map<String,String> mapSupplierWithAccount = new Map<String,String>();
          Database.SaveResult[] accountsResult = Database.insert( supplierAccounts , false ) ;
          
          for (Integer i = 0; i < accountsResult.size(); i++ ) {
              if(accountsResult[i].isSuccess()){
                  mapSupplierWithAccount.put(supplierIds[i],accountsResult[i].getId());
              }  
              else {
                    String ErrorMessage = 'ERROR ::' ;
                    // Operation failed, so get all errors                
                    for(Database.Error err : accountsResult[i].getErrors()) {
                        ErrorMessage += err.getMessage()  + '::';
                        System.debug('The following error has occurred.');                    
                        System.debug(err.getStatusCode() + ': ' + err.getMessage());
                        System.debug('Account fields that affected this error: ' + err.getFields());
                    }
                    mapSupplierWithAccount.put(supplierIds[i],ErrorMessage);
                }        
          }
          system.debug('Accounts are -->'+mapSupplierWithAccount);
          Map<String,String> mapSupplierWithAddress = new Map<String,String>();
          Database.SaveResult[] addressResult = Database.insert( supplierAccounts , false ) ;
          
          for (Integer i = 0; i < addressResult.size(); i++ ) {
              if(addressResult[i].isSuccess()){
                  mapSupplierWithAddress.put(supplierIds[i],addressResult[i].getId());
              }  
              else {
                    String ErrorMessage = 'ERROR ::' ;
                    // Operation failed, so get all errors                
                    for(Database.Error err : addressResult[i].getErrors()) {
                        ErrorMessage += err.getMessage()  + '::';
                        System.debug('The following error has occurred.');                    
                        System.debug(err.getStatusCode() + ': ' + err.getMessage());
                        System.debug('Account fields that affected this error: ' + err.getFields());
                    }
                    mapSupplierWithAddress.put(supplierIds[i],ErrorMessage);
                }        
          }
          system.debug('Addresses are -->'+mapSupplierWithAddress);
          List<MTX_AccountAddress__c> accountAddresses = new List<MTX_AccountAddress__c>();
          for(String supplierId : mapSupplierWithAccount.keySet()){
          
              if( ! mapSupplierWithAccount.get(supplierId).contains('ERROR ::')){
                  
                  if(! mapSupplierWithAddress.get(supplierId).contains('ERROR ::')){
              
                      MTX_AccountAddress__c accAddress = new MTX_AccountAddress__c();
                      accAddress.Account__c = mapSupplierWithAccount.get(supplierId) ;
                      accAddress.Address__c = mapSupplierWithAddress.get(supplierId) ;
                      accountAddresses.add(accAddress) ; 
                  
                  }
                  
                  Contact con = supplierContacts.get(supplierId);
                  con.AccountId = mapSupplierWithAccount.get(supplierId) ;
                  supplierContacts.put(supplierId, con);
                  
                    MTX_SupplierOracleAP__c supplier = new MTX_SupplierOracleAP__c(Id = supplierId);
                   supplier.ProcessDate__c = system.now();
                   supplier.ProcessStatus__c = 'Success' ;
                   //supplier.ErrorDescription__c = oracleSupplier.ErrorDescription__c ;
                   suppliersWithStatus.add(supplier);
                  
              }  
              
              else {
                   MTX_SupplierOracleAP__c supplier = new MTX_SupplierOracleAP__c(Id = supplierId);
                   supplier.ProcessDate__c = system.now();
                   supplier.ProcessStatus__c = 'Error' ;
                   supplier.ErrorDescription__c = mapSupplierWithAccount.get(supplierId) ;
                   suppliersWithStatus.add(supplier);
              }            
          }
          
          insert supplierContacts.values();
          insert accountAddresses ;
         
    
    }
    
    public void sendEmail(){
    
        // Reference the attachment page, pass in the account ID
        PageReference supplierPage = Page.MTX_SupplierLogFile;
        
        // Take the PDF content
        Blob b = supplierPage .getContent();
        
        OrgWideEmailAddress owa = [select id, DisplayName, Address from OrgWideEmailAddress limit 1];
        // Create the email attachment
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        efa.setFileName('supplierLog.txt');
        efa.setBody(b);
        
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        // Sets the paramaters of the email
        email.setSubject( 'Test Email for Supplier Log');
        email.setToAddresses( new List<String>{'VR00471039@techmahindra.com'});
        email.setPlainTextBody( 'Hello PFA.');
        email.setOrgWideEmailAddressId(owa.id);
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});

        // Sends the email
        Messaging.SendEmailResult [] r = 
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});   

    }

}
public class AvoidduplicateAccount{

public void AvoidDupliacteRecords(Account[] acc)
{
set<string> set1=new set<string>();
for(account a:[select id,name from Account])
{
set1.add(a.name);
}

for(Account d:Trigger.new)
{
if(set1.contains(d.name))
{
d.adderror('plz insert unique values');
}
}
}
}
trigger AccountAvoidDuplicate on account(before insert,before update)
{

set<string> set1=new set<string>();
for(account acc:[select id,name from account])
{

set1.add(acc.name);
}

for(account var:Trigger.new)
{
if(var.name!=null)
{
if(set1.contains(var.name))
{
var.adderror('plz insert unique values');
}

}
}
}
Trigger AccountAvoidDuplicate on Account(before insert,before update)
{
Map<id,account> map1=new map<id,account>();
list<account> acclist=[select id,name from account];
list<account> acclist1=new list<account>();
for(account acc:Trigger.new)
{
for(account a:acclist)
{
acclist1.add(a);
map1.putall(acclist1);


if(map1.containskey(acc.id))
{
acc.adderror('plz insert unique values');
}
}
}
}
 
Hi In below code if Account record is created,  that record goes into Notification Object.In the same way,if contact is created same record goes into Notification object.So for both Account and contact created ,Notification record should be created.So  what changes we need to do in below Apex class ..plz help anybody.
Apex class:


public  class NotificationServiceClass1 {

User varUser = [SELECT Id, Name FROM User WHERE Id =: UserInfo.getUserId()];

public void onAfterInsert(Account[] newAccounts){
     
        List<Notification__c> notifyInsertList = new list<Notification__c>();
        
        for(Account accName:newAccounts){        
        If(varUser.name =='santhosh konathala')
          {
            Notification__c notify=new Notification__c();
            notify.name=accname.name;
            notify.Action__c='Add';
          notify.Test__c='Outbound';
          notifyInsertList.add(notify);
          
          }
          else If(varUser.name == 'reddy kon'){
            Notification__c notify=new Notification__c();
            notify.name=accname.name;
            notify.Test__c='Inbound';
            notify.Action__c='Add';
            notifyInsertList.add(notify);
        }
        }  
        insert notifyInsertList;
        }        
        
       public void onAfterUpdate(Account[] newAccounts, map<id, Account> oldMap ){
    
            List<Notification__c> notifyUpdateList = new list<Notification__c>();
            for(Account acccountVar:newAccounts){
                    Account oldAcc = oldMap.get(acccountVar.Id);
                    if(oldAcc.name!=acccountVar.name){
                        If(varUser.name =='santhosh konathala'){
                                Notification__c notifyUpdate = new Notification__c();
                                notifyUpdate.name=acccountVar.name;
                                notifyUpdate.Action__c= 'Modify';
                              
                                notifyUpdate.Test__c='Outbound';
                                  notifyUpdateList.add(notifyUpdate);
                            }
                            else If(varUser.name == 'reddy kon'){
                            
                            Notification__c notifyUpdate = new Notification__c();
                            notifyUpdate.name=acccountVar.name;
                            notifyUpdate.Test__c='Inbound';
                            notifyUpdate.Action__c= 'Modify';
                            notifyUpdateList.add(notifyUpdate);
                        }
                }
            }
            
            
            if(notifyUpdateList.size()>0 && notifyUpdateList.size()!=null){
                insert notifyUpdateList;
            }
            
        }
}

Trigger code:

Trigger insertNotification1 on Account(after insert,after update) {

NotificationServiceClass1 handler=new NotificationServiceClass1();
if(Trigger.isinsert ){
   handler.OnAfterInsert(Trigger.new);
}
if(Trigger.isupdate ){
    handler.OnAfterUpdate(Trigger.new,Trigger.oldMap);

         }}
My Trigger code:

Trigger insertNotification1 on Account(after insert,after update) {

Notificationserviceclass1 handler=new Notificationserviceclass1();
if(Trigger.isinsert ){
   handler.OnAfterInsert(Trigger.new);
}
if(Trigger.isupdate ){
    handler.OnAfterUpdate(Trigger.new,Trigger.oldMap);

         }}

My Apex class--

public  class NotificationServiceClass1 {

public void onAfterInsert (Account[] newAccounts){
     
        List<Notification__c> notifyInsertList = new list<Notification__c>();
        for(Account accname:newAccounts){
        If(userinfo.getusername() == 'Kanaka konathala')
          {
            Notification__c notify=new Notification__c();
            notify.name=accname.name;
            notify.Action__c='Add';
          notify.Test__c='Outbound';
          }
          else 
            If(userinfo.getusername() == 'reddy kon'){
            Notification__c notify12=new Notification__c();
            notify12.name=accname.name;
            notify12.Test__c='Inbound';
            notifyInsertList.add(notify12);
        }
        if(notifyInsertList.size()>0)
        {
        insert notifyInsertList;
        }
    }
    }
    
    public void onAfterUpdate(Account[] newAccounts, map<id, Account> oldMap ){
        List<Notification__c> notifyUpdateList = new list<Notification__c>();
        for(Account Acc:newAccounts){
            Account oldAcc = oldMap.get(Acc.Id);
            if(Acc.name!=oldAcc.name){
            If(userinfo.getusername() == 'Kanaka konathala'){
                Notification__c notifyUpdate = new Notification__c();
                notifyUpdate.name=Acc.name;
                notifyUpdate.Action__c= 'Modify';
              
                notifyUpdate.Test__c='Outbound';
                }
                else
                If(userinfo.getusername() == 'reddy kon'){
                Notification__c notifyUpdate1 = new Notification__c();
                
                notifyUpdate1.Test__c='Inbound';
                notifyUpdateList.add(notifyUpdate1);
            }
        }
        
        if(notifyUpdateList.size()>0 && notifyUpdateList.size()!=null){
            insert notifyUpdateList;
        }
        
    }
}
}
 
public  class NotificationServiceClass {

public void onAfterInsert (Account[] newAccounts){
     
        List<Notification__c> notifyInsertList = new list<Notification__c>();
        for(Account accname:newAccounts){
            Notification__c notify=new Notification__c();
            notify.name=accname.name;
            notify.Action__c='Add';
          If(userinfo.getusername() == 'Kanaka konathala')
            notify.Test__c='Outbound';
            If(userinfo.getusername() == 'reddy kon')
            notify.Test__c='Inbound';
            notifyInsertList.add(notify);
        }
        insert notifyInsertList;
    }
    
    public void onAfterUpdate(Account[] newAccounts, map<id, Account> oldMap ){
        List<Notification__c> notifyUpdateList = new list<Notification__c>();
        for(Account Acc:newAccounts){
            Account oldAcc = oldMap.get(Acc.Id);
            if(Acc.name!=oldAcc.name){
                Notification__c notifyUpdate = new Notification__c();
                notifyUpdate.name=Acc.name;
                notifyUpdate.Action__c= 'Modify';
              If(userinfo.getusername() == 'Kanaka konathala')
                notifyUpdate.Test__c='Outbound';
                If(userinfo.getusername() == 'reddy kon')
                notifyUpdate.Test__c='Inbound';
                notifyUpdateList.add(notifyUpdate);
            }
        }
        
        if(notifyUpdateList.size()>0 && notifyUpdateList.size()!=null){
            insert notifyUpdateList;
        }
        
    }

 
Trigger createNotification on Account(After insert, After update)
{
list<Notification__c> notifyList = new list<Notification__c>();
list<user> varUser=[select id,name from user ];

for(account acc:Trigger.new)
{
if(varUser[0].name=='Kanaka konathala')
{
Notification__C notify=new Notification__C();
acc.name=notify.name;
notify.Test__C='Outbound';
notifylist.add(notify);
}
}
if(notifylist.size()>0)
{
insert notifylist;
}
}
public  class Notificationserviceclass {
List<Notification__c> notifylist1 = new list<Notification__c>();
List<Notification__c> notifylist2 = new list<Notification__c>();
public void onAfterInsert(Account[] newAccounts){
for(Account accname:newAccounts)
{
Notification__c notifyvar=new Notification__c();
notifyvar.name=accname.name;
notifyvar.Action__c='Add';
notifylist2.add(notifyvar);
}
insert notifylist2;
}
public void onAfterUpdate(Account[] newAccounts, map<id, Account> oldMap ){
 
for(Account Acc:newAccounts){
 
 Account oldname = oldMap.get(Acc.Id);
 
if(Acc.name!=oldname.name){
 
Notification__c memb = new Notification__c();
 
memb.name=Acc.name;
 
       memb.Action__c= 'Modify';
 
       notifylist1.add(memb);
 
       }
 
       if(notifylist1.size()>0 && notifylist1.size()!=null)
 
       {
 
       insert notifylist1;
 
       }
 
       }
 
     }
 
       }
 
Trigger insertNotification on Account(after insert,after update) {
List<Notification__c> member1 = new list<Notification__c>();
List<Notification__c> member2 = new list<Notification__c>();
  if(Trigger.isinsert)
   {
   for(account acclist:Trigger.new)
   {
   Notification__c nr=new notification__c();
   nr.name=acclist.name;
   nr.Action__c='Add';
   member2.add(nr);
   }
   insert member2;
   }
    if(Trigger.isupdate)
   {
   
 for(Account member:Trigger.new)
{
Account oldacc = Trigger.oldMap.get(member.Id);
if(member.name!=oldacc.name)
{

       Notification__c memb = new Notification__c();
       memb.name=member.name;
       memb.Action__c= 'Modify';
       member1.add(memb);
       }
       if(member1.size()>0 && member1.size()!=null)
       {
       insert member1;
       }
       }
       }
       }
Trigger insertNotification on Account(after insert,After update) {

 List<Notification__c> member1 = new list<Notification__c>();
 for(Account member:Trigger.new)
{
       Notification__c memb = new Notification__c();
       memb.name=member.name;
       member1.add(memb);
       }
       
       if(member1.size()>0 &&member1.size()!=null){
       insert member1;
       }
       }
Trigger insertNotification on Account(after insert,After update) {
Set<Id> set1= new Set<Id>();
 List<Notification__c> member1 = new list<Notification__c>();
 for(Account member:Trigger.new)
{
set1.add(member.Id);       
List<Account> memberList = [Select id,name from Account where id in:set1];
for(Account  temp :memberList )
{
List<Notification__c> member2 = new list<Notification__c>();
member2.name = temp.name;
member1.add(member2);

insert member1;
}
}
trigger Deleteres on Restintegration__c(after update) {
 List<Id> lstId = new List<Id>();

if(trigger.isupdate)
{
for(Restintegration__c res : trigger.new)
{
if(res.id != null)
{
lstId.add(res.id) ;
}
}
 }

for(Restintegration__c res: Trigger.old){
        List<Restintegration__c > existoppList =  [Select Id from Restintegration__c where  id in = lstId];
        delete existoppList;
    }
 
}
vf page:

<apex:page controller="AccountDelete" >
<apex:form >
<apex:outputlabel value="RecordToDelete "/>
  
<apex:inputText value="{!RecordToDelete}" label="RecordToDelete"/> <br/><br/>
<apex:outputlabel value="phone"/>
<apex:inputText label="phone"/><br/><br/>
<apex:commandButton value="Delete" action="{!DeleteName}"/>
<apex:param name="AccountDelete" value="abc" assignTo="{!RecordToDelete}"/>


</apex:form>

</apex:page>

Controller:

Public with sharing class AccountDelete{

Public Id RecordToDelete{get;set;}

Public List<account> acclist {get;set;}

public void DeleteName()
{
 acclist=Database.query('Select id from account where id=:'+ RecordToDelete);
system.debug('Record id to delete ='+ RecordToDelete);
if(acclist.size()>0 & acclist !=null)
{
delete acclist;
}
}
}

 
global class TechMDeletion implements Database.Batchable<sObject>
{   
    
    
  
    global Database.QueryLocator start(Database.BatchableContext bc)
    {
        date d=system.today().adddays(-30);        
        return Database.getQueryLocator([Select id from TechM__c where CreatedDate =:d]);


  
    } 
    
    
    
    global void execute(Database.BatchableContext BC, list<sObject> scope)
    {     
    system.debug('records fetched are'+scope);
        
 
        
            delete scope;   
            DataBase.emptyRecycleBin(scope); 
    }
    
    
    global void finish(Database.BatchableContext BC) 
    {                 
        
        
       
    }
}
trigger AccountAvoidDuplicate on account(before insert,before update)
{

set<string> set1=new set<string>();
for(account acc:[select id,name from account])
{

set1.add(acc.name);
}

for(account var:Trigger.new)
{
if(var.name!=null)
{
if(set1.contains(var.name))
{
var.adderror('plz insert unique values');
}

}
}
}
Trigger AccountAvoidDuplicate on Account(before insert,before update)
{
Map<id,account> map1=new map<id,account>();
list<account> acclist=[select id,name from account];
list<account> acclist1=new list<account>();
for(account acc:Trigger.new)
{
for(account a:acclist)
{
acclist1.add(a);
map1.putall(acclist1);


if(map1.containskey(acc.id))
{
acc.adderror('plz insert unique values');
}
}
}
}
 
My Trigger code:

Trigger insertNotification1 on Account(after insert,after update) {

Notificationserviceclass1 handler=new Notificationserviceclass1();
if(Trigger.isinsert ){
   handler.OnAfterInsert(Trigger.new);
}
if(Trigger.isupdate ){
    handler.OnAfterUpdate(Trigger.new,Trigger.oldMap);

         }}

My Apex class--

public  class NotificationServiceClass1 {

public void onAfterInsert (Account[] newAccounts){
     
        List<Notification__c> notifyInsertList = new list<Notification__c>();
        for(Account accname:newAccounts){
        If(userinfo.getusername() == 'Kanaka konathala')
          {
            Notification__c notify=new Notification__c();
            notify.name=accname.name;
            notify.Action__c='Add';
          notify.Test__c='Outbound';
          }
          else 
            If(userinfo.getusername() == 'reddy kon'){
            Notification__c notify12=new Notification__c();
            notify12.name=accname.name;
            notify12.Test__c='Inbound';
            notifyInsertList.add(notify12);
        }
        if(notifyInsertList.size()>0)
        {
        insert notifyInsertList;
        }
    }
    }
    
    public void onAfterUpdate(Account[] newAccounts, map<id, Account> oldMap ){
        List<Notification__c> notifyUpdateList = new list<Notification__c>();
        for(Account Acc:newAccounts){
            Account oldAcc = oldMap.get(Acc.Id);
            if(Acc.name!=oldAcc.name){
            If(userinfo.getusername() == 'Kanaka konathala'){
                Notification__c notifyUpdate = new Notification__c();
                notifyUpdate.name=Acc.name;
                notifyUpdate.Action__c= 'Modify';
              
                notifyUpdate.Test__c='Outbound';
                }
                else
                If(userinfo.getusername() == 'reddy kon'){
                Notification__c notifyUpdate1 = new Notification__c();
                
                notifyUpdate1.Test__c='Inbound';
                notifyUpdateList.add(notifyUpdate1);
            }
        }
        
        if(notifyUpdateList.size()>0 && notifyUpdateList.size()!=null){
            insert notifyUpdateList;
        }
        
    }
}
}
 
public  class NotificationServiceClass {

public void onAfterInsert (Account[] newAccounts){
     
        List<Notification__c> notifyInsertList = new list<Notification__c>();
        for(Account accname:newAccounts){
            Notification__c notify=new Notification__c();
            notify.name=accname.name;
            notify.Action__c='Add';
          If(userinfo.getusername() == 'Kanaka konathala')
            notify.Test__c='Outbound';
            If(userinfo.getusername() == 'reddy kon')
            notify.Test__c='Inbound';
            notifyInsertList.add(notify);
        }
        insert notifyInsertList;
    }
    
    public void onAfterUpdate(Account[] newAccounts, map<id, Account> oldMap ){
        List<Notification__c> notifyUpdateList = new list<Notification__c>();
        for(Account Acc:newAccounts){
            Account oldAcc = oldMap.get(Acc.Id);
            if(Acc.name!=oldAcc.name){
                Notification__c notifyUpdate = new Notification__c();
                notifyUpdate.name=Acc.name;
                notifyUpdate.Action__c= 'Modify';
              If(userinfo.getusername() == 'Kanaka konathala')
                notifyUpdate.Test__c='Outbound';
                If(userinfo.getusername() == 'reddy kon')
                notifyUpdate.Test__c='Inbound';
                notifyUpdateList.add(notifyUpdate);
            }
        }
        
        if(notifyUpdateList.size()>0 && notifyUpdateList.size()!=null){
            insert notifyUpdateList;
        }
        
    }

 
Trigger createNotification on Account(After insert, After update)
{
list<Notification__c> notifyList = new list<Notification__c>();
list<user> varUser=[select id,name from user ];

for(account acc:Trigger.new)
{
if(varUser[0].name=='Kanaka konathala')
{
Notification__C notify=new Notification__C();
acc.name=notify.name;
notify.Test__C='Outbound';
notifylist.add(notify);
}
}
if(notifylist.size()>0)
{
insert notifylist;
}
}