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
EricvEricv 

s-control to update a standard field

Hi
 
I have a custom field in account called lead source and I would like it to update the leads source in the opportunity when a new opportunity is created. We do not create opportunities when a Lead is converted they are created sometime after so I lose the visiablity to the lead source and our reps select random lead sources in Opportunity when I make it a required field.
 
I don't know much about java script or s-controls but I have been directed here by SFDC and they said I need to create an s-control to do this. According to them workflow rules will not work.
 
My though is this could be done by looking at the account ID then pulling the Account lead source and updating the Opportunity Lead source. But I can't find anything on how to do this anywhere. If someone has done this before could you please post your code or point me in the right direction?
 
Thanks,
E
Benjamin_PirihBenjamin_Pirih

I have done something similar to what your are speaking about..

You have a couple of options but 1st you should think about mapping the lead source to a contact or account when the lead is converted to a contact.  This is built in feature from lead to contact..  As you cannot relate an opportunity to a lead. 

Once you have the lead source at the account or contact level you then need to think about taking an action when an opportunity is created.  You can either create a custom s-control button which fires an api call to perform this action.  I.e. query the parent contact / account and get the lead source - then create an opportunity with this lead source..

or.  you can write an apex trigger on opportunity create to query the related account/contact object and populate it this way.  Much simplier if you understand apex and triggers. if you have a unique identifier from the contact/account to the lead you can query this lead and avoid the overhead of passing the lead source at conversion..

If your interested i could develop the code required as I already have something very similar..

Good Luck..

 

EricvEricv
Yes I would be intrested in that code I believe we have lead source from lead already mapped to Account, I know that it is a required field in the account level so I can pull the data from there. The problem I have with pulling it from Contact is that you might have more than one contact with diffrenet lead sources.
Benjamin_PirihBenjamin_Pirih
It can be done.. Look up OpportunityContactRole in the API guide..
 
You should be able to write a query like
 
Select id from opportunitycontactrole where opportunityid='111' and contactid='222' and isprimary = true
 
if id = null
{
 // update from account as not parent
}
else
{
 // is parent conact so update here
}
 
Good Luck
 
EricvEricv

Thanks for your help I am going to look into this.

 

E