You need to sign in to do that
Don't have an account?
TobyDog
Straight Forward Trigger for Beginner
Hi Guys,
I have a trigger creation question that I think is pretty striaght forward, however I'm still pretty new to APEX and wanted to see if you could help.
I have a custom object called Interest which contains two custom fields I want to update the opportunity with. There is a look-up relationship from the Interest to the Opportunity. Interest records (that already have the relevant fields populated) are automatically associated with opportunities when opportunities are created.
Custom Object : Interests
API Name: Interest__c
Fields on Interest Record
Core Lead ID
Api Name: Core_Lead_Id__c
Core Instance ID
API Name: Core_Instance_id__c
Fields on Opportunity
Core Lead ID
Api Name: Core_Lead_Id__c
Core Instance ID
API Name: Core_Instance_id__c
I want to populate the opportunity fields upon creation of the opportunity which happens at the conversion of a lead, although it really doesn't matter as long as it happens before the opportunity reaches the stage "Enrolled" There are 4 stages before. Let's call them. Stage 1, Stage 2, Stage, 3.
I have a trigger creation question that I think is pretty striaght forward, however I'm still pretty new to APEX and wanted to see if you could help.
I have a custom object called Interest which contains two custom fields I want to update the opportunity with. There is a look-up relationship from the Interest to the Opportunity. Interest records (that already have the relevant fields populated) are automatically associated with opportunities when opportunities are created.
Custom Object : Interests
API Name: Interest__c
Fields on Interest Record
Core Lead ID
Api Name: Core_Lead_Id__c
Core Instance ID
API Name: Core_Instance_id__c
Fields on Opportunity
Core Lead ID
Api Name: Core_Lead_Id__c
Core Instance ID
API Name: Core_Instance_id__c
I want to populate the opportunity fields upon creation of the opportunity which happens at the conversion of a lead, although it really doesn't matter as long as it happens before the opportunity reaches the stage "Enrolled" There are 4 stages before. Let's call them. Stage 1, Stage 2, Stage, 3.
Sample code(non bulkified) to copy information from Interest Object to Opportunity Object at the time of opp creation using the Core_Lead_Id__c field value :
trigger oppupdatefromInterest on Opportunity (after insert) {
Opportunity opp = trigger.new[0];
Interest__c int = [SELECT Core_Instance_id__c from Interest__c where Core_Lead_Id__c =:opp.Core_Lead_Id__c];//get Interest record where
opp.Core_Instance_id__c= int.Core_Instance_id__c;
update opp;
}
hoping I've understood the requirement correctly and the code helps!