You need to sign in to do that
Don't have an account?
Jim Montgomery
Trigger to insert lookup id on opportunity to another object
I have a custom object BI Retention that I need to link to opportunities.
Basically, if the DTN, month and year match, I want to insert the BI.ID into the BI lookup field on the opportunity.
Here is what I have so far, but getting error invalid foriegn key relationship BI_Retention_Quota.Retention_month__c.
trigger BI_Retention_Quota on Opportunity (before insert, before update) {
List<BI_Retention_Quota__c > BI = [select Retention_Month__c,Retention_DTN__C from BI_Retention_Quota__c ];
{
if(Trigger.isBefore)
{
if (Trigger.isInsert || Trigger.isUpdate)
{
for(Opportunity Opp : trigger.new)
{
for (BI_Retention_Quota__c b : BI)
{
if (b.retention_month__c.month = opp.retention_month__c.month && b.retention_month__c.year = opp.retention_month__c.year && b.retention_dtn__c = opp.renewal_rep_dtn__c)
{
opp.BI_Retention_Quota__c = b.Id;
}
}
}
}
}
}
}
Basically, if the DTN, month and year match, I want to insert the BI.ID into the BI lookup field on the opportunity.
Here is what I have so far, but getting error invalid foriegn key relationship BI_Retention_Quota.Retention_month__c.
trigger BI_Retention_Quota on Opportunity (before insert, before update) {
List<BI_Retention_Quota__c > BI = [select Retention_Month__c,Retention_DTN__C from BI_Retention_Quota__c ];
{
if(Trigger.isBefore)
{
if (Trigger.isInsert || Trigger.isUpdate)
{
for(Opportunity Opp : trigger.new)
{
for (BI_Retention_Quota__c b : BI)
{
if (b.retention_month__c.month = opp.retention_month__c.month && b.retention_month__c.year = opp.retention_month__c.year && b.retention_dtn__c = opp.renewal_rep_dtn__c)
{
opp.BI_Retention_Quota__c = b.Id;
}
}
}
}
}
}
}
Change your IF condition like this :
Use __r instead of __c:
if (b.retention_month__r.month = opp.retention_month__r.month && b.retention_month__r.year = opp.retention_month__r.year && b.retention_dtn__c = opp.renewal_rep_dtn__c)
Please mark as solved if this helps.
Regards
Medhya Mahajan