You need to sign in to do that
Don't have an account?
ckellie
Populating Field from Map
The below code is perplexing me. The concept is to look up the default account's language and return it to the Opportunity. The opportunity's language is note being updated. Below is the code:
public class DefaultOpportunityLanguage{ // These variables store Trigger.oldMap and Trigger.newMap Map<Id, Opportunity> oldOpps; Map<Id, Opportunity> newOpps; Map<Id, Account> accmap = new Map<Id, Account>(); Set<id> aid = new Set<id>(); Set<id> oid = new Set<id>(); String scountry; // This is the constructor // A map of the old and new records is expected as inputs public DefaultOpportunityLanguage( Map<Id, Opportunity> oldTriggerOpps, Map<Id, Opportunity> newTriggerOpps) { oldOpps = oldTriggerOpps; newOpps = newTriggerOpps; } // The one method your master trigger will call public void DefaultOpportunityLanguage() { string u = 'Angola'; Map<string, pw_cc__CountryObject__c> countrymap = new Map<string, pw_cc__CountryObject__c>(); for(pw_cc__CountryObject__c p : [select name,Primary_Language__c from pw_cc__CountryObject__c]){ countrymap.put(p.name, p); } system.debug('*************5countrymap size:' +countrymap.size()); for (Opportunity newOpp : oldOpps.values()) { system.debug('*************1accountid:' +newOpp.accountid); aid.add(newOpp.accountid); oid.add(newOpp.id); } for(account a : [select id, shippingcountry from account where id in:aid]){ accMap.put(a.id,a); } for (Opportunity newOpp : [select id, accountid, Language_to_prepare_docs_in__c from Opportunity where id =: oid]) { system.debug('*************3id:' +newOpp.id); scountry = accMap.get(newOpp.accountid).shippingCountry; system.debug('*************4scountry:' +scountry); if(countrymap.get(scountry).Primary_Language__c<>''){ newOpp.Language_to_prepare_docs_in__c = countrymap.get(scountry).Primary_Language__c; scountry = ''; } } } }The variable scountry is populated, the countrymap is populated, and I have confirmed that the database is complete with the appropriate records. But the language is not being written back tothe opportunity.
Please find the modified code:
Please do let me know if it helps you.
Regards,
Mahesh
All Answers
Can you please share your trigger code also. That would help us to understand the execution flow of your code and also helps us in providing a better solution for this.
Thanks,
Abhishek Bansal.
My general trigger calling the class is below. I have underlined the code that will call the class. Thank you
Please find the modified code:
Please do let me know if it helps you.
Regards,
Mahesh
Thank you for your help, your suggestion and one tweek solved the problem.
Thank you,
ckellie
Glad that your issue got resolved with the above code.
Please mark the best answer properly so that it will be helpful to others in the future. I think by mistake you selected thank you msg as a best answer.
Regards,
Mahesh