You need to sign in to do that
Don't have an account?
Ashw
how to put the below trigger code in class & call it from trigger, i'm a new stater i'm able to handle it in trigger
trigger InvoiceAccountUpdate on Client_Invoice__c (before insert,before update){ map<Id,Id> mapOppAccounts = new map<Id,Id>(); list<Id> lstOpportunityIds = new list<Id>(); for(Client_Invoice__c ObjInvoice : trigger.new){ lstOpportunityIds.add(objInvoice.opportunity__c); } list<Opportunity> lstopp = [select Id,Account.ID from Opportunity where Id In:lstOpportunityIds]; for(Opportunity objOpportunity : lstopp){ mapOppAccounts.put(objOpportunity.Id,objOpportunity.Account.Id); } for(Client_Invoice__c obj : trigger.new) { if(mapOppAccounts.get(obj.opportunity__c)!= Null) obj.Account__c= mapOppAccounts.get(obj.opportunity__c); } }
https://teachmesalesforce.wordpress.com/category/code-sample/
https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex_Trigger_Best_Practices (https://teachmesalesforce.wordpress.com/category/code-sample/)
Thanks for the reply, I gone through the web site thats reply usefull stuf but as a new stater it is too complex for me to understand it from that web so can i get direct code for this are any sample code please
For ex : Assume you create a separate class with two method updatedata and createData then you can easily call these two method from trigger by creating a instanse of that class if the method is non-static or call directly if these are static by using class name.
Example:
Hope this helps