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
steve456steve456 

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 

steve456steve456

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

 

 

Next

 

 

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

pradyprady

Use afterinsert trigger on lease to create new office record

 

You can check this url for how to do it

http://teachmesalesforce.wordpress.com/2011/05/16/trigger-to-create-a-new-record/

 

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

steve456steve456

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

pradyprady

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: Trigger.new)
    {
        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

http://forceschool.blogspot.com/2011/05/writing-apex-trigger-save-limits-in.html

steve456steve456

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;
 }