+ Start a Discussion
Sangram PhadkeSangram Phadke 

Calling apex class methods from trigger Plz help...

--------------------------Apex Class---------------------------
public class IA_scrum_apex_class {
public IA_Scrum__c scrum_class_var{get;set;}
public boolean chk1 { get; set; } 
public IA_Scrum__c scrumtime{get; private set;}


public IA_scrum_apex_class(ApexPages.StandardController controller) {
scrumtime = new IA_Scrum__c( Date_time_Scrum__c = DateTime.now() );
scrum_class_var = new IA_Scrum__c(); 
       
if(chk1==true){
scrum_class_var.Dump_test_field__c = 'Test check';
insert scrum_class_var;

}
}         
}

------------------------Trigger---------------
trigger IA_Scrum_Trigger on IA_Scrum__c (before update,before insert) {
for(IA_Scrum__c testclassapex1 : trigger.new){
//IA_scrum_apex_class =new IA_scrum_apex_class();---Show this error------Variable does not exist: IA_scrum_apex_class---------
// need sum vaue to be show & read visual force page vaues in Apex class then it invoked in trigger...........  
}
 
Bhavin Mehta 20Bhavin Mehta 20
trigger createlineitems on Order (before insert,after insert,before update)
{
 OrderproductComplete complete = 
        new OrderproductComplete(Trigger.oldMap, Trigger.newMap);
      complete.makecomplete();
}




public class OrderproductComplete {
Map<Id, Order> oldOrder;
Map<Id, Order> newOrder;
    
    public OrderproductComplete(
    Map<Id, Order> oldTriggerOrder, 
    Map<Id, Order> newTriggerOrder) {
      oldOrder = oldTriggerOrder;
      newOrder = newTriggerOrder;
  }
    
    public void makecomplete(){
        list<asset> addlineitems = new list<asset>();
        list<asset> updlineitems = new list<asset>();
        list<Orderitem> oitem = new list<Orderitem>();
        list<Orderitem> oitemfull = new list<Orderitem>();
        for (Order neword:newOrder.values())
        {
            Order oldord  = oldOrder.get(neword.Id);
      Boolean oldOrdIsCom = oldord.Status.equals('Complete');
      Boolean newOrdIsCom = neword.Status.equals('Complete');
      if (!oldOrdIsCom && newOrdIsCom) {
            
           oitem =  [select id,pricebookentry.product2id,pricebookentry.product2.name,Phone_Number__c,quantity,unitprice from orderitem where orderid = :neword.Id ];
            for (Orderitem oneorder : oitem)
            {
               Asset newasset = new Asset();
                
                newasset.AccountId = neword.AccountId;
                newasset.Product2Id =oneorder.PricebookEntry.product2id;
                newasset.Quantity = oneorder.Quantity;
                newasset.Phone_Number__c = oneorder.Phone_Number__c;
                newasset.Price = oneorder.UnitPrice;
                newasset.status = 'Purchased';
                newasset.InstallDate = System.today(); 
                newasset.Integration__c = oneorder.id;
                newasset.Name = oneorder.pricebookentry.product2.name;
                addlineitems.add(newasset);
               
                  
                
    }
          
        }
        
    }
        try{
    insert addlineitems;
    }
    catch (Exception e)
    {
        e.getMessage();
    }
       
       for (Order neword1:newOrder.values())
       {
           
           Order oldord1  = oldOrder.get(neword1.Id);
      Boolean oldOrdIsCom1 = oldord1.Status.equals('Complete');
      Boolean newOrdIsCom1 = neword1.Status.equals('Complete');
           if (!oldOrdIsCom1 && newOrdIsCom1)
           {
           oitemfull =  [select id,pricebookentry.product2id,pricebookentry.product2.name,Phone_Number__c,quantity,unitprice,Child_Product_del__c from orderitem where orderid = :neword1.Id and Child_Product_del__c <> null];
 		for (Orderitem updateorder : oitemfull)
        {
            
            asset updateasset = new asset();
            asset rootasset = new asset();
            updateasset=  [select id,name,Parasset__c,RootAssetId from asset where integration__c = :updateorder.Id] ;
            rootasset = [select id from asset where integration__c =:updateorder.Child_Product_del__c ];
            updateasset.Parasset__c = rootasset.id;
            updlineitems.add(updateasset);
          
        }
           
       }
       }
        try{
    update updlineitems;
    }
    catch (Exception e)
    {
        e.getMessage();
    }
       
        
    
}
    
}

Please check if the above mentioned code can help you.
Sangram PhadkeSangram Phadke
Thanks Bhavin Mehta.
I appreciate for above code.