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
Siva Krishna KondapalliSiva Krishna Kondapalli 

I am Trying to update Account Rating field Hot whenever Opportunity Stage is Closed Won

//when ever a record is inserted to the account automatically inserted to the contact// //limit reached the records //edhi oka doubt undi kanukovali// trigger Scenario1 on Account (after insert,before insert,before update,after update,before delete) {     User u = [SELECT Id,Name From User WHERE username = 'ramasiva094@gmail.com'];     List<Account>Acc = new List<Account>([SELECT Id,Name FROM Account WHERE createddate = today or lastmodifieddate = today]);     List<Contact>lstcons = new List<Contact>();     for(Account acc: trigger.new){         Contact con = new Contact();         con.LastName = acc.Name;         con.AccountId = acc.Id;         lstcons.add(con);         if(acc.NumberofLocations__c>2){           acc.adderror('reached limit today');             if(u.Name =='sivakrishna1837@gmail.com'){                 if(trigger.isdelete){                     for(Account acc2 : trigger.old){                         acc2.adderror('This Account cannot be deleted');                                              }                  }             }         if(trigger.Isupdate){             for(Account acc3 : trigger.new){                 acc3.adderror('ca not update');             }         }              if(trigger.isinsert){             for(Account acc4 : trigger.new){                 acc4.adderror('ca not insert');             }         }         }        }     insert lstcons;                          }
Siva Krishna KondapalliSiva Krishna Kondapalli
//when ever a record is inserted to the account automatically inserted to the contact//
//limit reached the records //edhi oka doubt undi kanukovali//
trigger Scenario1 on Account (after insert,before insert,before update,after update,before delete) {
    User u = [SELECT Id,Name From User WHERE username = 'ramasiva094@gmail.com'];
    List<Account>Acc = new List<Account>([SELECT Id,Name FROM Account WHERE createddate = today or lastmodifieddate = today]);
    List<Contact>lstcons = new List<Contact>();
    for(Account acc: trigger.new){
        Contact con = new Contact();
        con.LastName = acc.Name;
        con.AccountId = acc.Id;
        lstcons.add(con);
        if(acc.NumberofLocations__c>2){
          acc.adderror('reached limit today');
            if(u.Name =='sivakrishna1837@gmail.com'){
                if(trigger.isdelete){
                    for(Account acc2 : trigger.old){
                        acc2.adderror('This Account cannot be deleted');
                        
                    } 
                }
            }
        if(trigger.Isupdate){
            for(Account acc3 : trigger.new){
                acc3.adderror('ca not update');
            }
        }
             if(trigger.isinsert){
            for(Account acc4 : trigger.new){
                acc4.adderror('ca not insert');
            }
        }
        }
       }
    insert lstcons;
  
        
        
    }