You need to sign in to do that
Don't have an account?
Kev Brier
Auto update Look-up field in Opportunity from Custom Object
Our custom object is the Bidding element of the Opportunity (which we call Bid__c) and is a related list against the standard opportunity object. On the Opportunity we have created a Lookup Relationship to the bid object, which needs to be auto popluated with the related bid number. We have in past used Workflow/Field Update to acheive this type of scenairo but obviously this doesnt work for Lookup Relationships.
We have attempted to write our first trigger, we've got the stage that no error's are found but the trigger itself doesn't work. Code below:
trigger UpdateLookup on Opportunity (after insert, before update)
{
//instantiate set to hold unique Bid record ids
Set<Id> BidIds = new Set<Id>();
for(Opportunity s : Trigger.new)
{
BidIds.add(s.Bid_Name__c);
}
//instantiate map to hold deployment record Opportunity ids to their corresponding Bid Name
Map<Id, Bid__c> BidIdsMap = new Map<Id, Bid__c>([SELECT Id, Name FROM Bid__c WHERE Id IN: BidIds]);
for (Opportunity s : Trigger.new)
{
if (s.Name == null && BidIdsMap.containsKey(s.Bid_Name__c))
{
s.Name = BidIdsMap.get(s.Bid_Name__c).Name;
}
}
}
We've kind of hit a brick wall and would really appreciate any support or guidance?
Opportunity Lookup Field - Bid_Name__c
Custom Object - Bid__c
Related field that we required to populate the lookup - Name (standard field)
We have attempted to write our first trigger, we've got the stage that no error's are found but the trigger itself doesn't work. Code below:
trigger UpdateLookup on Opportunity (after insert, before update)
{
//instantiate set to hold unique Bid record ids
Set<Id> BidIds = new Set<Id>();
for(Opportunity s : Trigger.new)
{
BidIds.add(s.Bid_Name__c);
}
//instantiate map to hold deployment record Opportunity ids to their corresponding Bid Name
Map<Id, Bid__c> BidIdsMap = new Map<Id, Bid__c>([SELECT Id, Name FROM Bid__c WHERE Id IN: BidIds]);
for (Opportunity s : Trigger.new)
{
if (s.Name == null && BidIdsMap.containsKey(s.Bid_Name__c))
{
s.Name = BidIdsMap.get(s.Bid_Name__c).Name;
}
}
}
We've kind of hit a brick wall and would really appreciate any support or guidance?
Opportunity Lookup Field - Bid_Name__c
Custom Object - Bid__c
Related field that we required to populate the lookup - Name (standard field)
All Answers
But that may not be exactly what you are trying to do, I amy not be understanding exactly what you need. How does the business process work? If I create or edit an Opportunity, what determines which single Bid record should be linked to that Opportunity?
Guess a trigger is the best way but our knowledge of Apex is very weak - Hopefully you may be able to provide some advice?
We have then created a standard lookup field on the Opportunity to create the final link with the Opportunity & Bid and this is where the trigger needs to update automatically - We have additional functionaility that works on the back of this link being put in place but dont want the user to manually update, potentially adding the wrong bid to Opportunity, ideally the trigger auto populates and then we hide the field from the user.
In fairness we're probably out of our depth but need to figure this out for multiple reasons. Sorry to be pain