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

Ideas Plsss

I have an object called "Lease".When i create a record in Lease  it  gets saved.I should have a button  "Generate Office " in the record which automatically creates an office record which is exactly same as record created earlier in Lease


In " office" all the fields which are there in "lease" are present and also they are formula fields



I am in a confusion as i didnot understand d req properly or how do i need approach



Do i need to visual force page for the button

Marc G.ax1040Marc G.ax1040

After insert Trigger on Lease may help 


but every time when i change a field in lease is the particular field in  office also updated






How can i create an automatic Office record when a lease record is created


Use afterinsert trigger on lease to create new office record


You can check this url for how to do it


Similarly you can update the office object by using the afterupdate trigger on lease


Trigger to create new record works fine but whenever i make changes to the Lease Recorrd the newly created office record is not getting updated.  If i keep a  after update  then for even making a small update in the  Lease record a new duplicate office record is being created


what are you doing in update trigger?

Are you inserting a new record?


You need to search for the record from office object and update it.


    for (Quote  Q:
        if (Q.Discount__c!=System.Trigger.oldMap.get(Q.Id).Discount__c) // this will check if discount__c has changed
          //you can do your processing and updates here.


 Pls note : Make sure you bulkify your trigger. Maybe if you post the code someone could help you with that

This link could also help


This is the trigger which i wrote so far


trigger createOffice on Lease__c(after insert) {    
List<Offices__c> off = new List<Offices__c>();
    for (Lease__c newLease: Trigger.New){
                off.add (new Offices__c(
                     Name = newLease.Office_Id__c,
                     Address__c = newLease.Address__c,
                     City__c = newLease.City__c,
                     State__c = newLease.State__c));  
   insert off;