You need to sign in to do that
Don't have an account?
Greg Meszaros
Cannot access fields in loop for comparison and can't update records. Please help
I am trying to search through all records passed in by trigger and find ones where buyer zip codes matches an open Open Territory. The "Name" field on Open_Territory__c contains zip codes.
I am getting 2 errors. Variable does not exist: Name, and DML requires SObject or SObject list type: List<Id>.
Any help would be appreciated.
I am getting 2 errors. Variable does not exist: Name, and DML requires SObject or SObject list type: List<Id>.
Any help would be appreciated.
public static void setOpenTerritory(List<dealer__Sales_Up__c> triggerValues) { List<Open_Territory__c> openList = [SELECT Id, Name FROM Open_Territory__c WHERE Is_Active__c = true]; List<Id> suToUpdate = new List<Id>(); System.debug('openList contains ' + openList); // Search through all Sales Ups passed in trigger. Find ones with buyer zip codes matches Open Territory zip and add them to List. for(dealer__Sales_Up__c s : triggerValues) { if(s.dealer__Mailing_Zip__c === openList.Name){ s.Open_Territory__c = true; suToUpdate.add(s.Id); } } update suToUpdate; }
public static void setOpenTerritory(List<dealer__Sales_Up__c> triggerValues) {
List<Open_Territory__c> openList = [SELECT Id, Name FROM Open_Territory__c WHERE Is_Active__c = true];
System.debug('openList contains ' + openList);
list<string> zips = new list<string>();
for(Open_Territory__c op : openList){
zips.add(op.name);
}
for(dealer__Sales_Up__c s : triggerValues){
system.debug('===ter '+zips.contains(s.dealer__Mailing_Zip__c));
if(zips.contains(s.dealer__Mailing_Zip__c)){
s.Open_Territory__c = true;
}
}
}
All Answers
Hi Greg,
Please check once below sample code :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
public static void setOpenTerritory(List<dealer__Sales_Up__c> triggerValues) {
List<Open_Territory__c> openList = [SELECT Id, Name FROM Open_Territory__c WHERE Is_Active__c = true];
System.debug('openList contains ' + openList);
list<string> zips = new list<string>();
for(Open_Territory__c op : openList){
zips.add(op.name);
}
for(dealer__Sales_Up__c s : triggerValues){
system.debug('===ter '+zips.contains(s.dealer__Mailing_Zip__c));
if(zips.contains(s.dealer__Mailing_Zip__c)){
s.Open_Territory__c = true;
}
}
}