is working well when I give Direct Value as"'VIN__c='WAUZZZ8V3FA002049' ",But If I give dynamic Value as 'VIN__c=:setStrVINNumber" it is not working,Please have look the code in below:
String modelyear1;
String LMOI;
// loop through all contacts to be updated
String setStrVINNumber;
if(trigger.isBefore){
if (trigger.isInsert || trigger.isUpdate){
system.debug('-------333333-----1');
for(Contact Objcont:Trigger.New){
setStrVINNumber = Objcont.Id;
LMOI=Objcont.Latest_Model_of_Interest__c;
}
system.debug('ID..........'+ setStrVINNumber);
/*//////////////////////////////////////////////*/
if(LMOI == null){
system.debug('ID.......222222222222...'+ setStrVINNumber);
for(Contact_Vehicle_Ownership__c objCVO : [SELECT Id,VIN__c,Name,Model_Display_Name__c FROM
Contact_Vehicle_Ownership__c where VIN__c='WAUZZZ8V3FA002049' AND Customer_Vehicle_Relationship_Status__c='Active'])
{
modelyear1=objCVO.Model_Display_Name__c;
}
}
else
{
modelyear1=LMOI;
// Objcont.Current_Model__c=Objcont.Latest_Model_of_Interest__c;
}
for(Contact Objcont:Trigger.New){
Objcont.Current_Model__c=modelyear1;
}
Please let me know if any queries.
Thanks&Regards,KarthikBeacuse you are not setting VIN in setStrVINNumber field. You are adding contact id in that fieldsetStrVINNumber = Objcont.Id;please pass VIN in above line then you can use VIN__c=:setStrVINNumberLet us know if this will help youThanksAmit Chaudhary