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
pcasinellipcasinelli 

User Lookup Auto Population

First off, thanks in advance for any help with this question. I am relatively new to Salesforce.com and this is my first post! Woohoo! Anyway.....

 

I have two custom fields in my Opportunity page. The first is a required picklist called "Sales Assistance" and the second is a user lookup field called "Sales Resource." What I would like to happen is that if, when saving the opportunity, a user sets the Sales Resource picklist to "No" then the user lookup is automatically populated with the Opportunity owner. If it is yes, then the user will have to select a user on their own (and I have set up a validation rule for this already).

 

I can set up the workflow but field updates only allow me to select ONE specific user, not the user in a field. This is what my workflow rule currently says, in case this helps:

 

Rule CriteriaAND(
ISBLANK( Sales_Resource__c ) ,
ISPICKVAL(Sales_Assistance1__c , "NO" )
)
Evaluation CriteriaEvery time a record is created or edited

 

Thanks!

incuGuSincuGuS

Hey Pcasinelli,

 

Id have to look at workflows before im a bit rusty on them, but...

 

Would it be much trouble creating a Trigger that check/sets the data you want?

 

A trigger before Insert can check whether the field "salesAssistance__c" has been set to TRUE if it has check that the lookup is populated, if not then set the value of the lookup to the record's owner.

 

Something along the lines of: (havent tested/compiled)

 

 

trigger checkSalesAssistance on Opportunity (before insert) { 

// In case of many being inserted at once.
for (Integer i = 0; i < Trigger.new.size(); i++) {
Opportunity op = Trigger.new[i];

// If its NO, then assign the owner to the resource
if (op.Sales_Assistance__c == false) {
op.Sales_Resource__c = op.OwnerId
}
// If its YES, then require a value on the lookup or throw an error
else {
if(op.Sales_Resource__c == null) {
// Set the error that will appear if they try to
// insert one without a value in the lookup
Trigger.new[i].Sales_Resource__c.addError('cant be empty');
}
}
}
}

 

 

This is off the top of my head, dont qoute me on that code :P .

With a trigger like this one you can enforce that logic and also set whatever values you want.

 

Let me know if this helps you out ,

Gaston.

NeetikaNeetika

Helo,

I have one more requirement related to this question..If i want to auto populate field value at the time of filling details then???

Means above trigger works only when the record is saved then the autopopulated values comes in the fields..but i want when i fill the value in one field other fields automatically populate their values before saving the record..

can anyone give the solution for this??