• zAks
  • NEWBIE
  • 20 Points
  • Member since 2015
  • salesforce developer
  • BTL

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 7
    Replies
Hi All,
Beloe is the snippet:
trigger UpdateQuantity on SVMXC__Product_Stock__c (after insert,after update)
 {
   Set<Id> productIds = new Set<Id>();
    Map<Id, SVMXC__Product_Stock__c> productToStock = new Map<Id, SVMXC__Product_Stock__c>();
    for (SVMXC__Product_Stock__c stock : Trigger.new) 
    {
        if (stock.SVMXC__Product__c != null) 
        {
            productIds.add(stock.SVMXC__Product__c);
            productToStock.put(stock.Id, stock);
        }
    }
    
    Map<Id, Product2> productMap = new Map<Id, Product2>([SELECT Total_Available_Quantity__c FROM Product2 WHERE Id IN :productIds]);
     List<Product2> productsToUpdate = new List<Product2>();
      for(SVMXC__Product_Stock__c stock : trigger.new)
     {
     AggregateResult[] results = [Select SVMXC__Product__c,SUM(SVMXC__Quantity2__c) FROM SVMXC__Product_Stock__c GROUP BY SVMXC__Product__c];
     system.debug('tttt' + stock);
       //SVMXC__Product_Stock__c oldStock = trigger.oldMap.get(stock.Id);
           // System.debug('oldStockId'+ oldStock);
           Product2 product = productMap.get(stock.SVMXC__Product__c);
          if(stock.SVMXC__Status__c.equalsIgnoreCase('Available')) 
        {
           product.Total_Available_Quantity__c =    stock.SVMXC__Quantity2__c;
            system.debug('test' + product.Total_Available_Quantity__c);
             productsToUpdate.add(product);
     
         }
        
       /* if (oldStock.SVMXC__Status__c.equalsIgnoreCase('Available') && !stock.SVMXC__Status__c.equalsIgnoreCase('Available')) 
        {
        product.Total_Available_Quantity__c = product.Total_Available_Quantity__c - stock.SVMXC__Quantity2__c;
         productsToUpdate.add(product);
         system.debug('kkkk' + productsToUpdate);
         
        }*/

     }
     
      try {
        update productsToUpdate;
    } catch (Exception ex) 
    {
        System.debug(ex.getMessage());
    }
  
 }
  • February 11, 2017
  • Like
  • 0
Hi All, 

i have wrote a batch class ,But looks i am going Wrong Smewer , it shows 
 no viable alternative at character ' ' 


my code looks like :

global class RMABatchProcess implements Database.Batchable<sObject>{ 
     
     public String query ;              
     public List<RMA_Staging__c> RMAStgobj = new List<RMA_Staging__c>();
     public List<RMA_Staging_Lines__c> RMAStgLine = new List<RMA_Staging_Lines__c>();
     
    
     global RMABatchProcess() {            
        this.query = 'SELECT Id,Name,RecordTypeId,SM_Catalyst_RMA_Reason__c,SVMXC__Address_Type__c,SVMXC__Company__r.Name,SVMXC__Destination_City__c,SVMXC__Destination_Country__c,SVMXC__Destination_Location__r.Name,SVMXC__Destination_State__c,SVMXC__Destination_Street__c,SVMXC__Destination_Zip__c,SVMXC__Expected_Delivery_Date__c,SVMXC__Order_Status__c,SVMXC__Order_Type__c,SVMXC__Parts_Request__r.Name,SVMXC__Priority__c,SVMXC__RMA_Type__c,SVMXC__Service_Engineer__r.Name,SVMXC__Service_Order__r.Name,SVMXC__Source_City__c,SVMXC__Source_Country__c,SVMXC__Source_Location__r.Name,SVMXC__Source_State__c,(SELECT Id,Name,RecordTypeId,SVMXC__Actual_Quantity2__c,SVMXC__Actual_Receipt_Date__c,SVMXC__Disposition__c,SVMXC__Expected_Condition__c,SVMXC__Expected_Quantity2__c,SVMXC__Line_Status__c,SVMXC__Parts_Request_Line__r.Name,SVMXC__Product__r.Name,SVMXC__RMA_Shipment_Order__r.Name,SVMXC__Serial_Number__c,SVMXC__Service_Engineer__r.Name,SVMXC__Service_Order__r.Name FROM SVMXC__RMA_Shipment_Line__r WHERE SVMXC__Line_Status__c = \'Open\'),SVMXC__Source_Street__c,SVMXC__Source_Zip__c FROM SVMXC__RMA_Shipment_Order__c WHERE SVMXC__Order_Status__c = \'Open\' and RecordtypeId= \'012410000004qj3\'';        
    }
    
    global Database.QueryLocator start (Database.BatchableContext bc){
       return Database.getQueryLocator(query);
    }
    
    global void execute (Database.BatchableContext bc,List<sObject> scope){
       for (sObject obj : scope){
            SVMXC__RMA_Shipment_Order__c stageRMA = (SVMXC__RMA_Shipment_Order__c)obj;
            RMA_Staging__c RMAStg = new RMA_Staging__c();

            RMAStg.Name = stageRMA.Name;
            RMAStg.Order_Type__c = stageRMA.SVMXC__Order_Type__c;
            RMAStg.Address_Type__c = stageRMA.SVMXC__Address_Type__c;
            RMAStg.Expected_Delivery_Date__c = stageRMA.SVMXC__Expected_Delivery_Date__c;
            RMAStg.RMA_Type__c = stageRMA.SVMXC__RMA_Type__c;
            RMAStg.Service_Engineer__c = stageRMA.SVMXC__Service_Engineer__r.Name;
            RMAStg.Work_Order__c= stageRMA.SVMXC__Service_Order__r.Name;
            RMAStg.Account__c = stageRMA.SVMXC__Company__r.Name;
            RMAStg.From_City__c = stageRMA .SVMXC__Source_City__c;
            RMAStg.From_Country__c = stageRMA .SVMXC__Source_Country__c;
            RMAStg.From_Location__c = stageRMA .SVMXC__Source_Location__r.Name;
            RMAStg.From_State__c = stageRMA .SVMXC__Source_State__c ;                          
            RMAStg.From_Street__c = stageRMA .SVMXC__Source_Street__c;
            RMAStg.From_Zip__c = stageRMA .SVMXC__Source_Zip__c;            
            RMAStg.Order_Type__c = stageRMA .SVMXC__Order_Type__c; 
            RMAStg.Receiving_Notes__c = stageRMA.SVMXC__Shipping_Receiving_Notes__c ;
            RMAStg.RMA_Reason__c=  stageRMA.SM_Catalyst_RMA_Reason__c ;              
            RMAStg.To_City__c =stageRMA .SVMXC__Destination_City__c;
            RMAStg.To_Country__c = stageRMA .SVMXC__Destination_Country__c;
            RMAStg.To_Location__c = stageRMA .SVMXC__Destination_Location__r.Name;                                                   
            RMAStg.To_State__c = stageRMA .SVMXC__Destination_State__c;     
            RMAStg.To_street__c = stageRMA .SVMXC__Destination_Street__c;   
            RMAStg.To_Zip__c = stageRMA .SVMXC__Destination_Zip__c;                            
            RMAStgobj.add(RMAStg); 
            
            for(SVMXC__RMA_Shipment_Line__c RMA1_Line : stageRMA.SVMXC__RMA_Shipment_Line__r){
           
             if(stageRMA.SVMXC__Order_Status__c == 'Open'){
             RMA_Staging_Lines__c RMA_Line_stg = new RMA_Staging_Lines__c();
             RMA_Line_stg.Parts_Order__c = stageRMA.Name;
             RMA_Line_stg.Actual_Qty__c=POdrRMA1_Line_Line.SVMXC__Actual_Quantity2__c;
             RMA_Line_stg.Disposition__c = RMA1_Line.SVMXC__Disposition__c;
             RMA_Line_stg.Expected_Qty__c=RMA1_Line.SVMXC__Expected_Quantity2__c;
             RMA_Line_stg.Expected_Condition__c =RMA1_Line.SVMXC__Expected_Condition__c;
             RMA_Line_stg.IB_Serial_Number__c =RMA1_Line.SVMXC__Serial_Number__c;
             RMA_Line_stg.Actual_Receipt_Date__c =RMA1_Line.SVMXC__Actual_Receipt_Date__c;
             //RMA_Line_stg.Parts_Request_Line__c=RMA1_Line.SVMXC__Parts_Request_Line__r.Name;
             RMA_Line_stg.Product__c=RMA1_Line.SVMXC__Product__r.Name;
             RMA_Line_stg.Name = RMA1_Line.Name;
             RMAStgLine.add(RMA_Line_stg);
            }
           }              
        }
        try {  
            upsert RMAStgobj Name;  
            upsert RMAStgLine Name;   
   
        } catch (DmlException e) { 
            System.debug('Insertion of RMA and RMALines failed : '+e.getMessage());
        }
    } 
   
    global void finish (Database.BatchableContext bc){
     }
 }

thanks:
 
  • December 02, 2016
  • Like
  • 0
Hi all.
 i need to write a trigger for :
i have a requirment as , i have child object as Case ,In which their r 2 fields such as Assigned to and Technician Email.
and second parent object is Eqipment in which i have a field called as email.

wat i need is when ever the assigned field is not null in child, den Eqipment ;s email   should b copied to childs,s Technicain Email..



Thanks:
 
  • September 08, 2016
  • Like
  • 0
Hi.

i have 1time donation field on Transaction obj,This should be sumed up and update the field total amount on contact.
i have  a lookup on transaction to contact. how to write  batch apex fr this?



Thanks:
  • August 02, 2016
  • Like
  • 0
Hi,

I have PledgeAmount ,No.Installments,InstallmentPeriod​ fields on transaction object ,I wanted to calculate paydate on Installment object. when installment period is selected as monthly, biYearly,Yearly.And update paydate  on installment object


Thanks:
  • July 31, 2016
  • Like
  • 0
Hi,

 How to Create records on Installement object based on no of installment in transaction object which holds the amount divided by no of installments..




Thanks:
  • July 29, 2016
  • Like
  • 0
Hi All,
Beloe is the snippet:
trigger UpdateQuantity on SVMXC__Product_Stock__c (after insert,after update)
 {
   Set<Id> productIds = new Set<Id>();
    Map<Id, SVMXC__Product_Stock__c> productToStock = new Map<Id, SVMXC__Product_Stock__c>();
    for (SVMXC__Product_Stock__c stock : Trigger.new) 
    {
        if (stock.SVMXC__Product__c != null) 
        {
            productIds.add(stock.SVMXC__Product__c);
            productToStock.put(stock.Id, stock);
        }
    }
    
    Map<Id, Product2> productMap = new Map<Id, Product2>([SELECT Total_Available_Quantity__c FROM Product2 WHERE Id IN :productIds]);
     List<Product2> productsToUpdate = new List<Product2>();
      for(SVMXC__Product_Stock__c stock : trigger.new)
     {
     AggregateResult[] results = [Select SVMXC__Product__c,SUM(SVMXC__Quantity2__c) FROM SVMXC__Product_Stock__c GROUP BY SVMXC__Product__c];
     system.debug('tttt' + stock);
       //SVMXC__Product_Stock__c oldStock = trigger.oldMap.get(stock.Id);
           // System.debug('oldStockId'+ oldStock);
           Product2 product = productMap.get(stock.SVMXC__Product__c);
          if(stock.SVMXC__Status__c.equalsIgnoreCase('Available')) 
        {
           product.Total_Available_Quantity__c =    stock.SVMXC__Quantity2__c;
            system.debug('test' + product.Total_Available_Quantity__c);
             productsToUpdate.add(product);
     
         }
        
       /* if (oldStock.SVMXC__Status__c.equalsIgnoreCase('Available') && !stock.SVMXC__Status__c.equalsIgnoreCase('Available')) 
        {
        product.Total_Available_Quantity__c = product.Total_Available_Quantity__c - stock.SVMXC__Quantity2__c;
         productsToUpdate.add(product);
         system.debug('kkkk' + productsToUpdate);
         
        }*/

     }
     
      try {
        update productsToUpdate;
    } catch (Exception ex) 
    {
        System.debug(ex.getMessage());
    }
  
 }
  • February 11, 2017
  • Like
  • 0
Hi All, 

i have wrote a batch class ,But looks i am going Wrong Smewer , it shows 
 no viable alternative at character ' ' 


my code looks like :

global class RMABatchProcess implements Database.Batchable<sObject>{ 
     
     public String query ;              
     public List<RMA_Staging__c> RMAStgobj = new List<RMA_Staging__c>();
     public List<RMA_Staging_Lines__c> RMAStgLine = new List<RMA_Staging_Lines__c>();
     
    
     global RMABatchProcess() {            
        this.query = 'SELECT Id,Name,RecordTypeId,SM_Catalyst_RMA_Reason__c,SVMXC__Address_Type__c,SVMXC__Company__r.Name,SVMXC__Destination_City__c,SVMXC__Destination_Country__c,SVMXC__Destination_Location__r.Name,SVMXC__Destination_State__c,SVMXC__Destination_Street__c,SVMXC__Destination_Zip__c,SVMXC__Expected_Delivery_Date__c,SVMXC__Order_Status__c,SVMXC__Order_Type__c,SVMXC__Parts_Request__r.Name,SVMXC__Priority__c,SVMXC__RMA_Type__c,SVMXC__Service_Engineer__r.Name,SVMXC__Service_Order__r.Name,SVMXC__Source_City__c,SVMXC__Source_Country__c,SVMXC__Source_Location__r.Name,SVMXC__Source_State__c,(SELECT Id,Name,RecordTypeId,SVMXC__Actual_Quantity2__c,SVMXC__Actual_Receipt_Date__c,SVMXC__Disposition__c,SVMXC__Expected_Condition__c,SVMXC__Expected_Quantity2__c,SVMXC__Line_Status__c,SVMXC__Parts_Request_Line__r.Name,SVMXC__Product__r.Name,SVMXC__RMA_Shipment_Order__r.Name,SVMXC__Serial_Number__c,SVMXC__Service_Engineer__r.Name,SVMXC__Service_Order__r.Name FROM SVMXC__RMA_Shipment_Line__r WHERE SVMXC__Line_Status__c = \'Open\'),SVMXC__Source_Street__c,SVMXC__Source_Zip__c FROM SVMXC__RMA_Shipment_Order__c WHERE SVMXC__Order_Status__c = \'Open\' and RecordtypeId= \'012410000004qj3\'';        
    }
    
    global Database.QueryLocator start (Database.BatchableContext bc){
       return Database.getQueryLocator(query);
    }
    
    global void execute (Database.BatchableContext bc,List<sObject> scope){
       for (sObject obj : scope){
            SVMXC__RMA_Shipment_Order__c stageRMA = (SVMXC__RMA_Shipment_Order__c)obj;
            RMA_Staging__c RMAStg = new RMA_Staging__c();

            RMAStg.Name = stageRMA.Name;
            RMAStg.Order_Type__c = stageRMA.SVMXC__Order_Type__c;
            RMAStg.Address_Type__c = stageRMA.SVMXC__Address_Type__c;
            RMAStg.Expected_Delivery_Date__c = stageRMA.SVMXC__Expected_Delivery_Date__c;
            RMAStg.RMA_Type__c = stageRMA.SVMXC__RMA_Type__c;
            RMAStg.Service_Engineer__c = stageRMA.SVMXC__Service_Engineer__r.Name;
            RMAStg.Work_Order__c= stageRMA.SVMXC__Service_Order__r.Name;
            RMAStg.Account__c = stageRMA.SVMXC__Company__r.Name;
            RMAStg.From_City__c = stageRMA .SVMXC__Source_City__c;
            RMAStg.From_Country__c = stageRMA .SVMXC__Source_Country__c;
            RMAStg.From_Location__c = stageRMA .SVMXC__Source_Location__r.Name;
            RMAStg.From_State__c = stageRMA .SVMXC__Source_State__c ;                          
            RMAStg.From_Street__c = stageRMA .SVMXC__Source_Street__c;
            RMAStg.From_Zip__c = stageRMA .SVMXC__Source_Zip__c;            
            RMAStg.Order_Type__c = stageRMA .SVMXC__Order_Type__c; 
            RMAStg.Receiving_Notes__c = stageRMA.SVMXC__Shipping_Receiving_Notes__c ;
            RMAStg.RMA_Reason__c=  stageRMA.SM_Catalyst_RMA_Reason__c ;              
            RMAStg.To_City__c =stageRMA .SVMXC__Destination_City__c;
            RMAStg.To_Country__c = stageRMA .SVMXC__Destination_Country__c;
            RMAStg.To_Location__c = stageRMA .SVMXC__Destination_Location__r.Name;                                                   
            RMAStg.To_State__c = stageRMA .SVMXC__Destination_State__c;     
            RMAStg.To_street__c = stageRMA .SVMXC__Destination_Street__c;   
            RMAStg.To_Zip__c = stageRMA .SVMXC__Destination_Zip__c;                            
            RMAStgobj.add(RMAStg); 
            
            for(SVMXC__RMA_Shipment_Line__c RMA1_Line : stageRMA.SVMXC__RMA_Shipment_Line__r){
           
             if(stageRMA.SVMXC__Order_Status__c == 'Open'){
             RMA_Staging_Lines__c RMA_Line_stg = new RMA_Staging_Lines__c();
             RMA_Line_stg.Parts_Order__c = stageRMA.Name;
             RMA_Line_stg.Actual_Qty__c=POdrRMA1_Line_Line.SVMXC__Actual_Quantity2__c;
             RMA_Line_stg.Disposition__c = RMA1_Line.SVMXC__Disposition__c;
             RMA_Line_stg.Expected_Qty__c=RMA1_Line.SVMXC__Expected_Quantity2__c;
             RMA_Line_stg.Expected_Condition__c =RMA1_Line.SVMXC__Expected_Condition__c;
             RMA_Line_stg.IB_Serial_Number__c =RMA1_Line.SVMXC__Serial_Number__c;
             RMA_Line_stg.Actual_Receipt_Date__c =RMA1_Line.SVMXC__Actual_Receipt_Date__c;
             //RMA_Line_stg.Parts_Request_Line__c=RMA1_Line.SVMXC__Parts_Request_Line__r.Name;
             RMA_Line_stg.Product__c=RMA1_Line.SVMXC__Product__r.Name;
             RMA_Line_stg.Name = RMA1_Line.Name;
             RMAStgLine.add(RMA_Line_stg);
            }
           }              
        }
        try {  
            upsert RMAStgobj Name;  
            upsert RMAStgLine Name;   
   
        } catch (DmlException e) { 
            System.debug('Insertion of RMA and RMALines failed : '+e.getMessage());
        }
    } 
   
    global void finish (Database.BatchableContext bc){
     }
 }

thanks:
 
  • December 02, 2016
  • Like
  • 0
Hi,

I have PledgeAmount ,No.Installments,InstallmentPeriod​ fields on transaction object ,I wanted to calculate paydate on Installment object. when installment period is selected as monthly, biYearly,Yearly.And update paydate  on installment object


Thanks:
  • July 31, 2016
  • Like
  • 0
Hi,

 How to Create records on Installement object based on no of installment in transaction object which holds the amount divided by no of installments..




Thanks:
  • July 29, 2016
  • Like
  • 0