function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AshwAshw 

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);
        } 	
        
}

sweetzsweetz
Please have a look at this link. This may help you

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/)

AshwAshw
Thanks Sweetz

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 
Deepak Kumar ShyoranDeepak Kumar Shyoran
You can put the code which you have in trigger by crating a separate class and then call the method of that class from your trigger.
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.
sweetzsweetz
As deepak said, Put your logic inside a class and instantiate your class in your trigger and call the method .
Example:
Public class client{

onInsert(){
 Your logic
}

}

Trigger:
trigger InvoiceAccountUpdate on Client_Invoice__c (before insert,before update){
 //Instantiate your class
client c = new client();
c.onInsert(trigger.new);
}

Hope this helps