You need to sign in to do that
Don't have an account?
sudhirn@merunetworks.com
After Update After Insert
Hi,
I want to put below code inside after update after insert triger Please help me how to add below code into trigger am finding difficult in adding in inside trigger I need to pass trigger.new values in soql query.
Everytime when i make a update in lead it must look inside territory_lookup__c object to get values and update.
Thanks
Sudhir
I want to put below code inside after update after insert triger Please help me how to add below code into trigger am finding difficult in adding in inside trigger I need to pass trigger.new values in soql query.
Everytime when i make a update in lead it must look inside territory_lookup__c object to get values and update.
for (lead ulds : [select id,postalcode,state,country from lead where id = '00Q180000029Ujz' limit 1]) { ulds.postalcode = ''; ulds.country = 'India'; update ulds; } List<Territory_Lookup__c> territoryLookupList = null; List<Integer> gzip = new List<Integer>(); // we need a list so that we can sort it. list<String> gstate = new list<String>(); list<String> gcountry = new list<String>(); for(Lead l : [select id,postalcode,state,country from lead where id = '00Q180000029Ujz' limit 1]){ gstate.add(l.state); gcountry.add(l.country); if ( l.postalcode != null) { gzip.add(Integer.valueof(l.postalcode)); } else { gzip.add(0); } } system.debug('Zip :' + gzip); system.debug('State :' + gstate); system.debug('Country :' + gcountry); Territory_Lookup__c tls = [select Theater__c,Region__c,Area__c,User__c FROM Territory_Lookup__c where ( Zip_Start__c <= :gzip and Zip_End__c >=:gzip ) or (Country__c = :gcountry ) limit 1]; system.debug('Theater :' + tls.Theater__c); system.debug('Area :' + tls.Region__c); system.debug('Region :' + tls.Area__c); for(lead uld : [select id,postalcode,state,country from lead where id = '00Q180000029Ujz' limit 1]){ uld.Territory_Lookup__c = tls.id; uld.Territory_Area__c = tls.Area__c; uld.Territory_Region__c = tls.Region__c; uld.Territory_Theater__c = tls.Theater__c; update uld; }
Thanks
Sudhir
- loop through trigger.new?
- include some sort of information on those records based on fields that are filled out.
Generically, try something along these lines:There are a couple of problems with the original code that you wrote that you should consider:
All Answers
- loop through trigger.new?
- include some sort of information on those records based on fields that are filled out.
Generically, try something along these lines:There are a couple of problems with the original code that you wrote that you should consider:
Please use trigger.isinsert to the code you want to insert andd trigger.isupdate to the code block which you want to update.
Thanks
Gyani
http://www.mirketa.com
Thanks
Sudhir
best practice is that if you are updating any kinds of records, create separate class that will be called from trigger. Give me few hours and i will past test class to you.
Thank you
Peter
Thanks for you reply please send me a example of creating a seprate class and how to call that from trigget this will help me to resolve further issues.
Thanks in Advance
Sudhir
below you can find link to how to create apex class.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_class.htm
If you have your trigger already done please past it here. I would like to show you how to call class from trigger and how to make test class. You need to cover at least 70% of code.
Thank you
Peter