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
Amit Kr SinghAmit Kr Singh 

How to auto populate all lookup filed in child object using trigger

Hi All,
In my current scenario  I am having 3 objects.
1. Projects__c
2. Opportunity
3. Timeshaeet__c
 Project__c is lookup to opportunity and Timesheet __c object.
 opportunity is lookup to Timesheet__c object. so now if I am creating a timesheet from an opportunity object then both, opportunity and project lookup need to auto fill.
my Query screen shot


Hi Please provide me a trigger for my query.

Thanks,
Amit
GauravGargGauravGarg
Hi Amit,

There are two approach to acheive this:
1. By override "New" button, i.e. URL passing that would be easy to handle. You can go through like below link, and replace the Lookup ID field and it will populate data. 
/500/e?cas21=1&CF00NC0000005M2vR={!User.Name}&CF00NC0000005M2vR_lkid={!User.Id}

2. Trigger: 
  This approach will populate values only when user Click on "Save button", to populate data using trigger try below link:
https://developer.salesforce.com/forums/?id=906F0000000AtJ5IAK

Hope this helps!!!

Thanks,
Gaurav
skype: gaurav62990
Amit Kr SinghAmit Kr Singh
Hi please i am not geeting output please help...
GauravGargGauravGarg
Hi Amit,

Did you create any trigger or class to populate it?

Thanks,
Gaurav
Shiva RajendranShiva Rajendran
Hi Amit ,
I have tried your request on a contact object with a lookup to custom object  and it was working . i was able to populate contact and account lookup on the custom object named student__c  . I assume you want the autopopulate to happen on the edit screen of the timesheet record page

User-added image



Use the below code on the custom link you have to create
In the custom button choose content source as url 


https://shivamindtree-dev-ed.my.salesforce.com/a0J/e?CF00N2800000IpcR5={!Contact.Name}&CF00N2800000IpcR5_lkid={!Contact.Id}&CF00N2800000IpcRA={!Account.Name }&CF00N2800000IpcRA_lkid={! Account.Id }&retURL=%2F0032800000tsgYF

You have to modify the above lines as below
I will break it into fragments

//your salesforce id . In your case case it will be your oppurtunity Id
https://shivamindtree-dev-ed.my.salesforce.com/a0J/e? // copy the url from the oppurtunity record in ur org when it is in edit mode till e?

Then Open any Timesheet__c record in edit mode
go to inspect element
click on the Projects__c lookup ,You will get some value there lets assume that value as xxxxxxxxxxx
//replace this CF00N2800000IpcR5 with that value xxxxxxxxxxx and write {!Projects__r.Name}  instead of {!Contact.Name} And replace &CF00N2800000IpcR5_lkid={!Contact.Id} by & xxxxxxxxxxx_lkid={!Projects__r.id}

CF00N2800000IpcR5={!Contact.Name}&CF00N2800000IpcR5_lkid={!Contact.Id}

Repeat the same for Opportunity object in Timesheet__c record
GO to timesheet__c record
right click and inspect element
click on the oppurtunity__c element and get its id and do the same and replace the below lines
&CF00N2800000IpcRA={!Account.Name }&CF00N2800000IpcRA_lkid={! Account.Id }

Let me know if you need further help on this.
Thanks and Regards,
Shiva RV