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
sudhirn@merunetworks.comsudhirn@merunetworks.com 

Assign contact to opportunity

Hi,

  I need a suggestion in this requirement there is a contact lookup created in opportunity page this field should be updated automatically.

  When a lead is converted in salesforce it gets converted into Account, Opportunity and Contact my requirement is to update the contact information to opportunity lookup please suggest me can i create a trigger and update will this be a good approach or there is any alternative way like workflow we to update please suggest

Thanks
Sudhir
Sandy SwainSandy Swain
Hi Sudhir,

I completely understand your requirement.

Please contact me to discuss further SANDY@MIRKETA.COM.
Sandy

 
Gyanender SinghGyanender Singh
Hi Sudhir,

It can be done using trigger or may be process builder. i am not sure about process builder but it will done by trigger.

Thanks
Gyani
sudhirn@merunetworks.comsudhirn@merunetworks.com
Hi,

 Can i try something like below code
 
trigger OppFieldUpdate on Opportunity (after insert, after update) {
 if (!GlobalClass.runOnce){
    Opportunity[] updates = new Opporunity[] {};
    for (Opportunity opp: Trigger.new) {
        if (opp.StageName == 'Qualification') {
            updates.add(new Opportunity(Id = opp.Id, Opp.OppStatus__c = 'Won'));
        }
    }
    GlobalClass.runOnce = true;
    update updates;
 }
GlobalClass.runOnce = false;
}

Thanks
Sudhir
ajithMajithM
Hi, 

you can't use Work flow rule to populate lookup fields, you can either use Trigger or Process builder. Process Builder is not bulkified and has some known issues with bulkification (Too Many SOQL issues, even after using fastLookup and FastCreate in flows). So my suggestion is go with trigger. 
sudhirn@merunetworks.comsudhirn@merunetworks.com
I was able to achive this using below trigger 
 
trigger updateopportunitycontact on Lead (before update) 
{
for(Lead lead:System.Trigger.new) 
{ 

  if (lead.IsConverted) 
 { 
   Contact con = [SELECT Id FROM Contact WHERE Contact.Id = :lead.ConvertedContactId];
   Opportunity opp = [SELECT Contact__c from Opportunity where opportunity.id = :lead.ConvertedOpportunityId];
   
   opp.Contact__c = lead.ConvertedContactId;
   
   update opp;
  }
  
}

}

Thanks
Sudhir