You need to sign in to do that
Don't have an account?
BobP
Invalid loop variable type expected SObject
I am working on a trigger and keep getting the following error but i cant seem to find the issue with the code. Any help on this would be greatly appreciated.
public class supportClassForRequestUpdateOpps { Map<ID, Opportunity> parentOpps = new Map<ID, Opportunity>(); List<Id> listIds = new List<Id>();{ for (Request_for_Special_Payment__c relRec: trigger.new) { listIds.add(relRec.Opportunity_Name__c); } parentOpps = new Map<Id, Opportunity>([SELECT id, Special_Payment_Terms__c FROM Opportunity WHERE ID IN :listIds]); for (Request_for_Special_Payment__c r :Trigger.new){ Opportunity myParentOpp = parentOpps.get(r.Opportunity); if(r.Special_Payment_Terms__c == '') { myParentOpp.Special_Payment_Terms__c = r.Requested_Payment_Terms__c; } } update parentOpps.values(); } }
1 . You need to wrap You logic in method like below
2 .You need to use Opportunity__c from Request_for_Special_Payment__c
Opportunity myParentOpp = parentOpps.get(r.Opportunity__c);
Here is the compleet code
Error: Compile Error: Variable does not exist: Opportunity__c at line 19 column 48
In the Line 19 please use your Opportunity Lookup Field API Name from Request_for_Special_Payment__c Object:
Opportunity myParentOpp = parentOpps.get( Here Use your Opportunity Field Api Name );
Thanks,
Maharajan.C
Error: Compile Error: Variable does not exist: Special_Payment_Terms__c at line 21 column 10
I updated the code below and I was able to save it but nothing happening when I try to update the Opportunity the Special_Payment_Terms__c field remains blank. I did have a incorrect feild name so I changed it to Required_Payment_Terms__c
Try the below updated code:
public class supportClassForRequestUpdateOpps {
public static void updateOpp(List<Request_for_Special_Payment__c> listOfRerSer){
Map<ID, Opportunity> parentOpps = new Map<ID, Opportunity>();
Set<Id> setIds = new set<Id>();
for(Request_for_Special_Payment__c relRec: listOfRerSer)
{
setIds.add(relRec.Opportunity_Name__c);
}
parentOpps = new Map<Id, Opportunity>([SELECT id, Special_Payment_Terms__c
FROM Opportunity
WHERE ID IN :setIds]);
for (Request_for_Special_Payment__c r :listOfRerSer){
if(parentOpps.containsKey(r.Opportunity_Name__c))
{
if(parentOpps.get(r.Opportunity_Name__c).Special_Payment_Terms__c == '')
{
parentOpps.get(r.Opportunity_Name__c).Special_Payment_Terms__c = r.Requested_Payment_Terms__c;
}
}
}
if(!parentOpps.isEmpty())
update parentOpps.values();
}
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Maharajan.C
Thank you for your help. Igettingthe following error
Error: Compile Error: Variable does not exist: Requested_Payment_Terms__c at line 23 column 88
Thank you everyone for your help