You need to sign in to do that
Don't have an account?
NetD
Help: Auto Populate a a custom look-up field on a custom object
Hi, I am not a coder so I would very much appreciate some help on how to code the follow simple trigger (i think):
I have a custom object that embedded in the Opportunity object with master-detail relationship.
On this custom object I have created a custom look-up field to relate with the User object.
What I need is a trigger to auto-populate this "User " look-up field with the "Opportunity Owner" whenever a record is created on this custom object.
Please help me! thank you!!
Thanks for your response Rabi.
I have a custom object named "Stage Payments" that has master-detail relationship with Opportunity object, basically this custom object stores payment/invoice info inside each opportunity, so for exmaple if there is one invoice for this opportunity, there will be one "stage payment" record. For sales performance calculation reasons, I need to link "stage payment" record to "User" object, so the system can identify the amount of payment inside this stage payment is related to a particular "User" profile, and this user is the "Opportunity Owner" in the Opportunity object.
I have created a look-up relationship field inside the "stage payment" custom object called "Quota User", and related the field to "User" object.
I need a trigger to auto-populate the "Quota User" field with the "Opportunity Owner" of the opportunity that this "Stage payment" is related to - whenever a stage payment record is created.
Hope this explains a little bit better.....
Thanks!
Hi,
We cannot auto populate through triggers how ever we can do it with the help of URL encoding.
see this article:
http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html
Over ride button and pass values of fields as parameters.
Thanks
Query opportunity's owner and stamp it in custom lookup field.
I have created the below trigger code for the custom object, to query the opportunity owner.
Comes back with error: unexpected token: 'Map' line 8..
Could someone please help?
For reference the code below
trigger autopopulatequotauser on Milestone__c (before Insert, before Update) {
List<Id> oppIds = new List<Id>();
for(Milestone__c m :trigger.new){
oppIds.add(m.Opportunity__c);
}
Map<Id,Opportunity__r> = new Map <Id, Opportunity__r> ([select Owner, StageName, Ready_for_Quote_Generation__c from Opportuntiy__r where id in:oppIds]);
for(Milestone__c mi: trigger.new){
if(!oppMap.IsEmpty()){
String stage = oppMap.get(mi.Opportunity__r).StageName;
Boolean review = oppMap.get(mi.Opportunity__r).Ready_for_Quote_Generation__c;
if ((stage ='50% - Final Two' && review ='True')||(stage ='75% - Verbal' && review ='True')||(stage ='90% - Contracts/ Order Forms' && review ='True')|| (stage ='Closed Won' && review ='True'))
{
if(!oppMap.get(mi.Opportunity__r).Owner = mi.User__c)
{
mi.User__c = oppMap.get(mi.Opportunity__r).Owner;
}
}
}
}
}
Map<Id,Opportunity__c> oppMap = new Map <Id, Opportunity__c> ([select Owner, StageName, Ready_for_Quote_Generation__c from Opportuntiy__c where id in:oppIds]);
i have changed the coding accordingly, yet there is still the same error.
Code::
trigger autopopulatequotauser on Milestone__c (before Insert, before Update) {
List<Id> oppIds = new List<Id>();
for(Milestone__c m :trigger.new){
oppIds.add(m.Opportunity__c);
}
Map<Id,Opportunity__c> = new Map <Id, Opportunity__c> ([select Owner, StageName, Ready_for_Quote_Generation__c from Opportuntiy__c where id in:oppIds]);
for(Milestone__c mi: trigger.new){
if(!oppMap.IsEmpty()){
String stage = oppMap.get(mi.Opportunity__c).StageName;
Boolean review = oppMap.get(mi.Opportunity__c).Ready_for_Quote_Generation__c;
if ((stage ='50% - Final Two' && review ='True')||(stage ='75% - Verbal' && review ='True')||(stage ='90% - Contracts/ Order Forms' && review ='True')|| (stage ='Closed Won' && review ='True'))
{
if(!oppMap.get(mi.Opportunity__c).Owner = mi.User__c)
{
mi.User__c = oppMap.get(mi.Opportunity__c).Owner;
}
}
}
}
}