Using Trigger Updating Lookup filed.

To Update the Lookup field, Using Trigger Before Insert, Before Update.

Here I’am assuming Opportunity as Child and Budget_Master__c as Parent Object.
The Criteria is The From_Date__c(Date filed) & To_Date__c(Date filed) From Budget_Master__c must be in the range of given Opportunity RecCreatedDate__c(Datetime field)

trigger UpdateLookup on Opportunity (Before Insert,Before update) {
if(trigger.isInsert || trigger.isUpdate){
set<Budget_Master__c> BudMaster = new Set<Budget_Master__c>([Select Id, Name, From_Date__c,To_Date__c From Budget_Master__c]);

for(Opportunity  Op :{
for(Budget_Master__c BM :BudMaster ){
system.debug('------BFR IF---- ');
system.debug('------RecCreatedDate : '+(Op.RecCreatedDate__c).date());
 system.debug('------From: ' +BM.From_Date__c);
 system.debug('------ToDt: '+BM.To_Date__c );
If(  (((Op.RecCreatedDate__c).date()) >= BM.From_Date__c) && ((Op.RecCreatedDate__c).date()) <=(BM.To_Date__c)) {
system.debug('------InSide IF---- ');
}//If closed
}//Inner for CLOSED
}//outer for CLOSED
}//if(trigger.isInsert || trigger.isUpdate) CLOSED
}//Trigger closed

One thought on “Using Trigger Updating Lookup filed.

  1. This web page is mostly a stroll-via for the entire info you needed about this and didn’t know who to ask. Glimpse here, and also you’ll definitely uncover it. [Reply]


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s