You need to sign in to do that
Don't have an account?

Error: Compile Error: Comparison arguments must be compatible types: Schema.SObjectField
Hi,
There are two objects named Opportunity and Equipment. They are related using a Junction object named "Opportunity_Equipment__c".
Whenever there is an Equipment with status as "Pending Sale" and the related Opportunity Stagename is "Closed Lost" or Closed Abandoned", i need to delete the equipment.
trigger cascadeJunctionDelete on Opportunity_Equipment__c (after update) {
List<Opportunity> oppList = new List<Opportunity>();
List<Equipment__c> eqList = new List<Equipment__c>();
for(Opportunity_Equipment__c ed : Trigger.old) {
if((Opportunity.StageName == 'Closed Lost' || Opportunity.StageName == 'Closed-Abandoned') && ( Equipment__c.Status__c == 'Pending Sales') ) {
oppList.add(new Opportunity(id=ed.Opportunity__c));
eqList.add(new Equipment__c(id=ed.Equipment__c)); }
}
if(eqList.size() > 0) {
delete eqList;
}
}
But am geeting an error while saving this :
Error: Compile Error: Comparison arguments must be compatible types: Schema.SObjectField, String at line 10 column 5
i.e. at the highlighted line
I think you need a trigger on Opportunity instead of Opportunity Equipment.
Use this,
Deactivate the old trigger.
All Answers
the error is occure because in IF statment you write Opportunity.stageName == 'Closed Lost'
So here Opportunity is SObject not a instance of SObject.
First you have to query to access the fields of Related object.
Note : This code is not Tested
Error: Compile Error: Variable does not exist: ed.Equipment__c at line 20 column 40
Use this instead,
tried your code, it saved , but the deletion did not happen
sorry that's my mistak
replace line 20 with
Is this condition returns true for your data set?
((opp.StageName == 'Closed Lost' || opp.StageName == 'Closed-Abandoned') && ( eq.Status__c == 'Pending Sales'))
You may use debug logs to test it.
i checked the debug log, this trigger is not in business.
i could not find this in the log itself. is this not running when i update an opportunity ?
trigger cascadeJunctionDelete on Opportunity_Equipment__c (after update, after insert)
no success, the equipment is not getting deleted
and i dont find this trigger running in the Debug Log.
Any suggestion?
I think you need a trigger on Opportunity instead of Opportunity Equipment.
Use this,
Deactivate the old trigger.