• Somasundaram S 1
  • NEWBIE
  • 90 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 55
    Questions
  • 68
    Replies
am using standard object if some of the record reaches certain condition i would like to display warning message when end user open the record
how to do it
one way i can create VF page and based on the condition i will set record type and open the VF page other than this i just create computed text field and use the formula to display the message other than these two is there any easy way to prompt the warning message please advise me
 
i a object called call and another object called transaction , this transaction is related to call , i would like to update a field in transaction when the call is submitted how to do it ? which is the best method. the reason i want to update is i want to invoke a trigger at transaction  when the call is submitted . i dont want to write trigger in call object . once i update the field in when call is submitted then trigger will invoke in transaction
please advise me  
HI All
       could you please advise me about test case i wrote for the  the below test class and when i run it shows it covered 82% but am not convinced, the trigger code has after update,after insert, after delete and after undelte , in all i just getting the id of child and parent then i am collectiing child record then getting sum and then updateing the parent field. 
in below test class i just inserted what are the record need for the code but it shows 82% code coverage , for prod move this is fine but my query is how come it covered 82& i didnt do anything for after update after delete undelete and also didnt get sum and update 
could you please advise me
 
trigger quantityleft on Sample_Transaction__c ( after INSERT, after UPDATE, after DELETE, after UNDELETE ) {
   List<Sample_Lot__c> list_lot= new List<Sample_Lot__c>();
     Set<Id> set_transaction = new Set<Id>();
     Decimal Sum = 0;
      if( Trigger.isInsert || Trigger.isUndelete ){
        for( Sample_Transaction__c objOpp: Trigger.new ) {
            if( objOpp.Completed_Transaction__c == TRUE ){
                set_transaction.add( objOpp.Parent_id__c );
            }
        }
    }
 

    if( Trigger.isUpdate ) {

        for( Sample_Transaction__c objOpp: Trigger.new ) {

            if( objOpp.Completed_Transaction__c == TRUE ) {

                set_transaction.add( objOpp.Parent_id__c );

            }

        }

    }
 

    if( Trigger.isdelete ) {

       for( Sample_Transaction__c objOpp: Trigger.old ) {

            if( objOpp.Completed_Transaction__c == TRUE ) {

                set_transaction.add( objOpp.Parent_id__c );
            }
          }
    }
    List<Sample_Transaction__c> sampleTransactionRecords = new List<Sample_Transaction__c>();
    sampleTransactionRecords = [
        SELECT  Id
                ,Sample_Lot_ID__c

                ,Transaction_Quantity__c,
                Completed_Transaction__c

        FROM    Sample_Transaction__c

        WHERE   Parent_id__c = :set_transaction

    ];
    List<String> sampleLotIds = new List<String>();
    for( Sample_Transaction__c sampleTransaction : sampleTransactionRecords ) {
        sampleLotIds.add( sampleTransaction.Sample_Lot_ID__c );
    }
    List<Sample_Lot__c> sampleLotRecords = new List<Sample_Lot__c>();
    sampleLotRecords = [
        SELECT  Id
                ,Name
                ,Quantity_Left__c
        FROM    Sample_Lot__c
        WHERE   Id IN :set_transaction

    ];


    Map<String,Sample_Lot__c> mapOfSampleLots = new Map<String,Sample_Lot__c>();

    for( Sample_Lot__c sampleLot : sampleLotRecords ) {

        mapOfSampleLots.put( sampleLot.Id, sampleLot );

    }
    

    if( !set_transaction.isEmpty() ) {

        List<Sample_Lot__c> sampleLotsToUpdate = new List<Sample_Lot__c>();

        
        for( Sample_Transaction__c sample_transaction : sampleTransactionRecords ) {
         if( sample_transaction.Completed_Transaction__c == TRUE ) {

            Sum += sample_transaction.Transaction_Quantity__c;

 
}
        }
}
 for( Sample_Lot__c samplelots : sampleLotRecords ) {

         samplelots.Quantity_left__c=Sum;


    }


        UPDATE sampleLotRecords;

    

}

test class

 
@isTest 
public class testquantityleft{
static testmethod void triggerTest(){
// create account
Account accountOb= new Account();
accountOb.Firstname='name';
accountOb.LastName='1';
accountOb.Credentials__c='MD';
accountOb.SLN__c='123';
accountOb.Specialty_1__c='heart';
Map <String,Schema.RecordTypeInfo> recordTypeMap = Account.sObjectType.getDescribe().getRecordTypeInfosByName();
//Account accountObj = new Account();
//accountObj.name = 'Test Record Type';
if(recordTypeMap.containsKey('Reckitt Person Account')) {
 accountOb.RecordTypeId= recordTypeMap.get('Reckitt Person Account').getRecordTypeId();
}
insert accountOb;
// create address
Address__c address = new Address__c();
address.Account__c = accountOb.id;
//Map <String,Schema.RecordTypeInfo> recordTypeMap1 = Address__c.sObjectType.getDescribe().getRecordTypeInfosByName();
//if(recordTypeMap1.containsKey('Reckitt Address')) {
 //address .RecordTypeId= recordTypeMap.get('Reckitt Address').getRecordTypeId();
//}
address.Name='somaaddress';
insert address;

// create product
Product__c prod = new Product__c();
prod.name ='test';
insert prod;
Sample_Lot__c lot=new Sample_Lot__c();
lot.Name='test lot';
lot.Product_ID__c=prod.id;
lot.Confirmed_Quantity__c=600;
lot.Quantity_Left__c=0;
insert lot;

// create sample transaction

Sample_Transaction__c stransac = new Sample_Transaction__c();
stransac.Account_ID__c = accountob.id;
stransac .Address_ID__c=address.id;
stransac .Quantity__c =100;
stransac .Product__c=prod.id;
stransac .Sample_Lot_ID__c=lot.id;
insert stransac ;
Sample_Transaction__c stransac1 = new Sample_Transaction__c();
stransac1.Account_ID__c = accountob.id;
stransac1 .Address_ID__c=address.id;
stransac1 .Quantity__c =100;
stransac1 .Product__c=prod.id;
stransac1 .Sample_Lot_ID__c=lot.id;
Map <String,Schema.RecordTypeInfo> recordTypeMap2 = Sample_Transaction__c.sObjectType.getDescribe().getRecordTypeInfosByName();
if(recordTypeMap2.containsKey('Reckitt Receipt')) {
 stransac1 .RecordTypeId= recordTypeMap2.get('Reckitt Receipt').getRecordTypeId();
}





insert stransac1 ;





}
}

i am using the after insert,after update,after delete,after undelete events in my trigger while writing test class 
do i need to write for each event please advise
 
trigger quantityleft on Sample_Transaction__c (after insert,after update,after delete,after undelete) {
    List<Sample_Lot__c> list_lot= new List<Sample_Lot__c>();
    set<Id> set_Opportunity = new set<Id>();
     if(Trigger.isInsert || Trigger.isUndelete){
        for(Sample_Transaction__c objOpp: trigger.new){
        
        if(objOpp.Completed_Transaction__c == true){
         set_Opportunity.add(objOpp.Parent_id__c);
         //set_Opportunity.add(objOpp.id);
           }
    }
    }
    
    if(Trigger.isUpdate){
        for(Sample_Transaction__c objOpp: trigger.new){
        
        if(objOpp.Completed_Transaction__c == true){
        set_Opportunity.add(objOpp.Parent_id__c);
//        set_Opportunity.add(objOpp.id);
           }
  }
    
    
    }
    
    if(Trigger.isdelete){
        for(Sample_Transaction__c objOpp: trigger.old){
        
        if(objOpp.Completed_Transaction__c == true){
set_Opportunity.add(objOpp.Parent_id__c);
           }
  
    }
    
    }

    if(!set_Opportunity.isEmpty()){
    
    
    
                 Decimal Sum;
       Sum=0;

  for(Sample_Transaction__c sample_transaction : [SELECT id,Completed_Transaction__c,Sample_Lot_ID__c, Transaction_Quantity__c FROM Sample_Transaction__c WHERE Parent_id__c = : set_Opportunity

]){

           if(sample_transaction.Completed_Transaction__c ){
           system.debug('eeeeeeeeeeeeeeeeeeeeeeeeeeeee');
            Sum+= sample_transaction.Transaction_Quantity__c;
  
   }
  
    for(Sample_Lot__c objLot: [SELECT Id, Quantity_Left__c FROM Sample_Lot__c WHERE Id = : sample_transaction.Sample_Lot_ID__c]){

 

            objlot.Quantity_left__c = Sum ;

            list_lot.add(objlot);

 update objLot;

        }
        
 }
}

    
}


 
I have a parent object and child object and am updating the sum of child records to a field in parent
do my below code cover governor limit please advise. 
trigger quantityleft on Sample_Transaction__c (after insert,after update,after delete,after undelete) {
    List<Sample_Lot__c> list_Account= new List<Sample_Lot__c>();
    set<Id> set_Opportunity = new set<Id>();
     if(Trigger.isInsert || Trigger.isUndelete){
        for(Sample_Transaction__c objOpp: trigger.new){
        
        if(objOpp.Completed_Transaction__c == true){
         set_Opportunity.add(objOpp.Parent_id__c);
           }
    }
    }
    
    if(Trigger.isUpdate){
        for(Sample_Transaction__c objOpp: trigger.new){
        
        if(objOpp.Completed_Transaction__c == true){
         set_Opportunity.add(objOpp.Parent_id__c);
           }
  }
    
    
    }
    
    if(Trigger.isdelete){
        for(Sample_Transaction__c objOpp: trigger.old){
        
        if(objOpp.Completed_Transaction__c == true){
         set_Opportunity.add(objOpp.Parent_id__c);
           }
  
    }
    
    }

    if(!set_Opportunity.isEmpty()){
    
    
    
                 Decimal Sum;
       Sum=0;

  for(Sample_Transaction__c sample_transaction : [SELECT id,Sample_Lot_ID__c, Transaction_Quantity__c FROM Sample_Transaction__c WHERE Parent_id__c = : set_Opportunity

]){
            
            Sum+= sample_transaction.Transaction_Quantity__c;
  
    
    for(Sample_Lot__c objAccount : [SELECT Id, Quantity_Left__c FROM Sample_Lot__c WHERE Id = : sample_transaction.Sample_Lot_ID__c]){

 

            objAccount.Quantity_left__c = Sum ;

            list_Account.add(objAccount);

 update objAccount ;

        }
        
 }
}

    
}

 
i have parent and child and would like to udpate sum of a field from child collection to parent field its working fine for insert and udpate when i delete it throughs error where am i missing the code 
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger quantityleft caused an unexpected exception, contact your administrator: quantityleft: execution of AfterDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.quantityleft: line 4, column 1".

 
trigger quantityleft on Sample_Transaction__c (after insert,after update,after delete,after undelete) {
    List<Sample_Lot__c> list_Account= new List<Sample_Lot__c>();
    set<Id> set_Opportunity = new set<Id>();
         for(Sample_Transaction__c objOpp: trigger.new){
         set_Opportunity.add(objOpp.Parent_id__c);
   }
        Decimal Sum;
       Sum=0;

  for(Sample_Transaction__c sample_transaction : [SELECT id,Sample_Lot_ID__c, Transaction_Quantity__c FROM Sample_Transaction__c WHERE Parent_id__c = : set_Opportunity

]){
            
            Sum+= sample_transaction.Transaction_Quantity__c;
  
    
    for(Sample_Lot__c objAccount : [SELECT Id, Quantity_Left__c FROM Sample_Lot__c WHERE Id = : sample_transaction.Sample_Lot_ID__c]){

 

            objAccount.Quantity_left__c = Sum ;

            list_Account.add(objAccount);

 update objAccount ;

        }
        
 }


    
}

 
In below code am getting , am trying so many different method sample lot is parent and sample transaction is child could you please suggets me what is the reason for below error
Compile Error: Didn't understand relationship 'Sample_Transaction__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 44

 
trigger quantityleft on Sample_Transaction__c (after insert,after update,after delete,after undelete) {
    List<Sample_Lot__c> list_Account= new List<Sample_Lot__c>();
     set<Id> set_Opportunity = new set<Id>();
         for(Sample_Transaction__c objOpp: trigger.new){
        set_Opportunity.add(objOpp.Sample_Lot_ID__c);
    }
    Decimal Sum;
            for(Sample_Lot__c objAccount : [SELECT Id,(SELECT Id,sample_lot FROM Sample_Transaction__c),Quantity_Left__c FROM Sample_Lot__c WHERE Id IN: set_Opportunity]){
        Sum=0;
                        
        for(Sample_Transaction__c objOpp01: objAccount.Quantity_Left__c){
            Sum+=objOpp01.Confirmed_Quantity__c ;
        }
        objAccount.Quantity_left__c =Sum;
        list_Account.add(objAccount);
    }
    update list_Account;
}

 
I am getting below error while update the value in parent record from the child reocrds collection
Apex trigger Totalquanityleft caused an unexpected exception, contact your administrator: Totalquanityleft: execution of AfterUpdate caused by: System.TypeException: Invalid id value for this SObject type: a0i0E0000000YDuQAM: Trigger.Totalquanityleft: line 31, column 1
My apologies am not so good in cdoing
sample lot is parent object, sample tarnsaction is child , quantiyty left is parent obecjt field, total quantity is child object field 
 
trigger Totalquanityleft   on Sample_Transaction__c( after insert, after update,after delete,after undelete) {
     Set<Id> transactionIdSet=new Set<Id>();
     List<Sample_Lot__c> ordListToUpdate=new List<Sample_Lot__c>();
     if(Trigger.isInsert || Trigger.isUndelete){
          for(Sample_Transaction__c qnty: Trigger.new){
             if(qnty.id != null){
                transactionIdSet.add(qnty.Id);
             }    
          }

     }

     if(Trigger.isUpdate){
        for(Sample_Transaction__c qnty: Trigger.new){
             if(qnty.id != null && qnty.Transaction_Quantity__c != trigger.oldMap.get(qnty.Id).Transaction_Quantity__c){
                 transactionIdSet.add(qnty.Id);
             }    
         }
     }
     If(Trigger.isDelete){
        for(Sample_Transaction__c qnty : Trigger.old){
            if(qnty.Id != null){
                 transactionIdSet.add(qnty.Id);
           }     
        }

   }

    if(!transactionIdSet.isEmpty()){
        for(AggregateResult res : [SELECT id,sum(Transaction_Quantity__c)can FROM Sample_Transaction__c  WHERE id IN :transactionIdSet GROUP BY id]) {
        ordListToUpdate.add(new Sample_Lot__c (Id=(Id)res.get('Sample_Lot__c.id'),Quantity_Left__c=(Double)res.get('can')));
        //ordListToUpdate.add(new Order(Id=(Id)res.get('OrderId'),Total_Pieces1__c=(Double)res.get('can')));    
           
           
        }
        
    }
    if(!ordListToUpdate.isEmpty()){
        try{
            update ordListToUpdate;
         }catch(DmlException de){
            System.debug(de);
         }



     }



}

 
I have a reuiqrement i want to have a field in parent record and get the sum of a field from all child record. this is lookup relationship record. how to do in a easy way , please suggest me.
I would like to open a dasboard based on user login ,i use below VF code and please suggets me how to implement the logic to open the dashboard based on user log-in
<apex:page >
<apex:pageBlock title="My Dashboard" mode="edit">
            <apex:pageBlockSection title="My Dashboard" columns="1" collapsible="false">
                               <apex:outputLink title="My Dashboard" value="{!URLFOR('/01Z9E0000000EWK')}">My Dashboard</apex:outputLink>
            </apex:pageBlockSection>
            </apex:pageBlock>
</apex:page>
i have 3 different dash board for same profile user , based on user login i would like to open the dashboard . I would like to create VF.
Only simple VF enough? or do i need to have apexclass . How to do this and  please advise me.
thanks
Hi
    Account record is territory based and one particular user couldnt serach account record based on phone number and address , any suggestion?
but the other user with same profile for different territoy aboe to search record
error afterupdate
I got below error
"update failed  Cannot_insert_update_activate_entity samplelotprocess: execution of afterupdate caused by ssytem dmlexception :update failed" 

i noticed error shows in line no 82 at the time of update any idea why please advise me


trigger SampleLotProcess on Sample_Lot__c (after insert, after update) {
    class SampleLotProcessHandler {
        Sample_Lot__c[] oldRows;
        Sample_Lot__c[] newRows;
        Map<Id, Sample_Lot__c> oldMap;
        Map<Id, Sample_Lot__c> newMap;
        
    Map<String, RecordType> rtMap;
        
        
        public void initialize(Sample_Lot__c[] oldRows, Sample_Lot__c[] newRows, Map<Id, Sample_Lot__c> oldMap, Map<Id, Sample_Lot__c> newMap) {
            this.oldRows = oldRows;
            this.newRows = newRows;
            this.oldMap = oldMap;
            this.newMap = newMap;
           
        }

        public void onAfterInsert() {
            createReceipts();
        }
        
        public void onAfterUpdate() {
            createReceipts();
        }   
        
        public void createReceipts() {
            Sample_Lot__c[] filteredRows = new Sample_Lot__c[0];
            Set<Id> transferIds = new Set<Id>();
            for (Sample_Lot__c item : newRows) {
                if (item.Status__c != 'Confirmed') continue;
                if (oldMap != null && item.Status__c == oldMap.get(item.Id).Status__c) continue;
                
                filteredRows.add(item);
                if (item.Original_Transfer_Transaction__c != null) {
                  transferIds.add(item.Original_Transfer_Transaction__c);
                }
            }            
            
            Sample_Transaction__c[] transfers = [select id, Status__c, Transferred_From__c  from Sample_Transaction__c where id in :transferIds];
            Map<Id, Sample_Transaction__c> transferMap;
            if (transfers.isEmpty()) {
                transferMap = new Map<Id, Sample_Transaction__c>();
            } else {
                transferMap = new Map<Id, Sample_Transaction__c>(transfers);
            }
            
            Sample_Transaction__c[] forIns = new Sample_Transaction__c[0];
            
            for (Sample_Lot__c item : filteredRows) {
                if (item.Status__c != 'Confirmed') continue;
                if (oldMap != null && item.Status__c == oldMap.get(item.Id).Status__c) continue;
                
                Sample_Transaction__c newReceipt = new Sample_Transaction__c();
                newReceipt.Transfer_To__c = item.OwnerId;
                newReceipt.Comments__c = item.Comments__c;
                newReceipt.Quantity__c = item.Confirmed_Quantity__c;
                newReceipt.OwnerId = item.OwnerId;
                newReceipt.Transfer_To__c = item.OwnerId;
                
                if (transferMap.containsKey(item.Original_Transfer_Transaction__c)) {
                    newReceipt.Transferred_From__c = transferMap.get(item.Original_Transfer_Transaction__c).Transferred_From__c;
                    transferMap.get(item.Original_Transfer_Transaction__c).Status__c = 'Confirmed';
                }
                
                if (getRtMap().containsKey('Reckitt_Receipt')) {
                    newReceipt.RecordTypeId = getRtMap().get('Reckitt_Receipt').Id;
                }     
                
                newReceipt.Product__c = item.Product_ID__c;
                newReceipt.Sample_Lot_ID__c = item.Id;
                newReceipt.Transaction_Date__c = Date.today();
                
                forIns.add(newReceipt);
            }
            
            if (!forIns.isEmpty()) {
                insert forIns;
            }
            
            if (!transferMap.isEmpty()) {
                update transferMap.values();
            }
        }
        
        public Map<String, RecordType> getRtMap() {
            if (rtMap == null) {
                rtMap = new Map<String, RecordType>();
                
                RecordType[] rtList = [select id, DeveloperName from RecordType where SObjectType = 'Sample_Transaction__c'];
                
                for (RecordType item : rtList) {
                    rtMap.put(item.DeveloperName, item);
                }
            }
            
            return rtMap;
        }
    }
    
    SampleLotProcessHandler handler = new SampleLotProcessHandler();
    handler.initialize(trigger.old, trigger.new, trigger.oldMap, trigger.newMap);
    
    if (trigger.isAfter && trigger.isInsert) {
        handler.onAfterInsert();
    } else if (trigger.isAfter && trigger.isUpdate) {
        handler.onAfterUpdate();
    }
}
Error in js script
I am using below VF page and calling JS script function , when i click the confirm button the value is not displaying in the popup 

 when i click the confirm button the value is not getting and displaying i gave VF oage and JS function any idea why the value is not displaying
pls advise
User-added image
VF Page
<apex:pageBlockTable value="{!pendingLots}" var="item">
                        <apex:column headerValue="Action">
                            <apex:outputLink value="#" onclick="jsConfirmReceipt('{!item.Id}');">Confirm</apex:outputLink>
                        </apex:column>
                        <apex:column headerValue="{!$ObjectType.Product__c.fields.Name.label}" value="{!item.Product_ID__r.Name}"/>
                        <apex:column headerValue="{!$ObjectType.Sample_Lot__c.fields.Name.label}" value="{!item.Name}"/>
                        <apex:column headerValue="{!$ObjectType.Sample_Lot__c.fields.Expiration_Date__c.label}" value="{!item.Expiration_Date__c}"/>                        
                        <apex:column headerValue="{!$ObjectType.Sample_Lot__c.fields.Shipped_Quantity__c.label}" value="{!item.Shipped_Quantity__c}"/>    
                        <apex:column headerValue="{!$ObjectType.Sample_Lot__c.fields.Shipped_Date__c.label}" value="{!item.Shipped_Date__c}"/>
                    </apex:pageBlockTable>   

JS Function

 function jsConfirmReceipt(aRowId) {
            rowid = aRowId;

            var pp = $j("#pSource div");
            showPopup('Confirm Receipt', pp.html(), 400, 300);
            
            if (receipts) {
                item =  $j.grep(receipts, function(e){ return e.Id == rowid; });
                if (item && item.length != 0) {
                    popupbox = $j("#" + window.box.id);
                    //popupbox.find('[data-id="from"]').text(item[0].Original_Transfer_Transaction__r.Owner.Name);
                    popupbox.find('[data-id="expirationDate"]').text(item[0].Expiration_Date__c);
                    popupbox.find('[data-id="lotName"]').text(item[0].Name);
                    popupbox.find('[data-id="shipmentDate"]').text(item[0].Shipped_Date__c);
                    popupbox.find('[data-id="product"]').text(item[0].Product_ID__r.Name);
                    popupbox.find('[data-id="quantity"]').text(item[0].Shipped_Quantity__c);

                }
                console.log(item);
            }            
        }
I got below error
"update failed  Cannot_insert_update_activate_entity samplelotprocess: execution of afterupdate caused by ssytem dmlexception :update failed" 

i noticed error shows in line no 82 at the time of update any idea why please advise me


trigger SampleLotProcess on Sample_Lot__c (after insert, after update) {
    class SampleLotProcessHandler {
        Sample_Lot__c[] oldRows;
        Sample_Lot__c[] newRows;
        Map<Id, Sample_Lot__c> oldMap;
        Map<Id, Sample_Lot__c> newMap;
        
    Map<String, RecordType> rtMap;
        
        
        public void initialize(Sample_Lot__c[] oldRows, Sample_Lot__c[] newRows, Map<Id, Sample_Lot__c> oldMap, Map<Id, Sample_Lot__c> newMap) {
            this.oldRows = oldRows;
            this.newRows = newRows;
            this.oldMap = oldMap;
            this.newMap = newMap;
           
        }

        public void onAfterInsert() {
            createReceipts();
        }
        
        public void onAfterUpdate() {
            createReceipts();
        }   
        
        public void createReceipts() {
            Sample_Lot__c[] filteredRows = new Sample_Lot__c[0];
            Set<Id> transferIds = new Set<Id>();
            for (Sample_Lot__c item : newRows) {
                if (item.Status__c != 'Confirmed') continue;
                if (oldMap != null && item.Status__c == oldMap.get(item.Id).Status__c) continue;
                
                filteredRows.add(item);
                if (item.Original_Transfer_Transaction__c != null) {
                  transferIds.add(item.Original_Transfer_Transaction__c);
                }
            }            
            
            Sample_Transaction__c[] transfers = [select id, Status__c, Transferred_From__c  from Sample_Transaction__c where id in :transferIds];
            Map<Id, Sample_Transaction__c> transferMap;
            if (transfers.isEmpty()) {
                transferMap = new Map<Id, Sample_Transaction__c>();
            } else {
                transferMap = new Map<Id, Sample_Transaction__c>(transfers);
            }
            
            Sample_Transaction__c[] forIns = new Sample_Transaction__c[0];
            
            for (Sample_Lot__c item : filteredRows) {
                if (item.Status__c != 'Confirmed') continue;
                if (oldMap != null && item.Status__c == oldMap.get(item.Id).Status__c) continue;
                
                Sample_Transaction__c newReceipt = new Sample_Transaction__c();
                newReceipt.Transfer_To__c = item.OwnerId;
                newReceipt.Comments__c = item.Comments__c;
                newReceipt.Quantity__c = item.Confirmed_Quantity__c;
                newReceipt.OwnerId = item.OwnerId;
                newReceipt.Transfer_To__c = item.OwnerId;
                
                if (transferMap.containsKey(item.Original_Transfer_Transaction__c)) {
                    newReceipt.Transferred_From__c = transferMap.get(item.Original_Transfer_Transaction__c).Transferred_From__c;
                    transferMap.get(item.Original_Transfer_Transaction__c).Status__c = 'Confirmed';
                }
                
                if (getRtMap().containsKey('Reckitt_Receipt')) {
                    newReceipt.RecordTypeId = getRtMap().get('Reckitt_Receipt').Id;
                }     
                
                newReceipt.Product__c = item.Product_ID__c;
                newReceipt.Sample_Lot_ID__c = item.Id;
                newReceipt.Transaction_Date__c = Date.today();
                
                forIns.add(newReceipt);
            }
            
            if (!forIns.isEmpty()) {
                insert forIns;
            }
            
            if (!transferMap.isEmpty()) {
                update transferMap.values();
            }
        }
        
        public Map<String, RecordType> getRtMap() {
            if (rtMap == null) {
                rtMap = new Map<String, RecordType>();
                
                RecordType[] rtList = [select id, DeveloperName from RecordType where SObjectType = 'Sample_Transaction__c'];
                
                for (RecordType item : rtList) {
                    rtMap.put(item.DeveloperName, item);
                }
            }
            
            return rtMap;
        }
    }
    
    SampleLotProcessHandler handler = new SampleLotProcessHandler();
    handler.initialize(trigger.old, trigger.new, trigger.oldMap, trigger.newMap);
    
    if (trigger.isAfter && trigger.isInsert) {
        handler.onAfterInsert();
    } else if (trigger.isAfter && trigger.isUpdate) {
        handler.onAfterUpdate();
    }
}
 
I am using below VF page and calling JS script function , when i click the confirm button the value is not displaying in the popup 

 when i lick the confirm button the value is not getting and displaying i gave VF oage and JS function any idea why the value is not displaying pls advise
User-added image
VF Page
<apex:pageBlockTable value="{!pendingLots}" var="item">
                        <apex:column headerValue="Action">
                            <apex:outputLink value="#" onclick="jsConfirmReceipt('{!item.Id}');">Confirm</apex:outputLink>
                        </apex:column>
                        <apex:column headerValue="{!$ObjectType.Product__c.fields.Name.label}" value="{!item.Product_ID__r.Name}"/>
                        <apex:column headerValue="{!$ObjectType.Sample_Lot__c.fields.Name.label}" value="{!item.Name}"/>
                        <apex:column headerValue="{!$ObjectType.Sample_Lot__c.fields.Expiration_Date__c.label}" value="{!item.Expiration_Date__c}"/>                        
                        <apex:column headerValue="{!$ObjectType.Sample_Lot__c.fields.Shipped_Quantity__c.label}" value="{!item.Shipped_Quantity__c}"/>    
                        <apex:column headerValue="{!$ObjectType.Sample_Lot__c.fields.Shipped_Date__c.label}" value="{!item.Shipped_Date__c}"/>
                    </apex:pageBlockTable>   

JS Function

 function jsConfirmReceipt(aRowId) {
            rowid = aRowId;

            var pp = $j("#pSource div");
            showPopup('Confirm Receipt', pp.html(), 400, 300);
            
            if (receipts) {
                item =  $j.grep(receipts, function(e){ return e.Id == rowid; });
                if (item && item.length != 0) {
                    popupbox = $j("#" + window.box.id);
                    //popupbox.find('[data-id="from"]').text(item[0].Original_Transfer_Transaction__r.Owner.Name);
                    popupbox.find('[data-id="expirationDate"]').text(item[0].Expiration_Date__c);
                    popupbox.find('[data-id="lotName"]').text(item[0].Name);
                    popupbox.find('[data-id="shipmentDate"]').text(item[0].Shipped_Date__c);
                    popupbox.find('[data-id="product"]').text(item[0].Product_ID__r.Name);
                    popupbox.find('[data-id="quantity"]').text(item[0].Shipped_Quantity__c);

                }
                console.log(item);
            }            
        }
Hi All
             Whenever a user Id is locked due to wrong password entered, we need to send an email to a specific group of admins [other than the locked user].Is this possible? Please advise me.
I asked above question in success forum and understand this is not feasible. if any one has any suggestion/idea please share 
thanks

 
HI All
         I have a test field in my system , is it possible to use vlookup to avoid duplicate entry for this text field. Please advise.
thanks
ss
 
Hi
    I got below error and i have given trigger and also test class , could you please suggets me 
System.DmlException: Update failed. First exception on row 0 with id a0i4E000000t7jmQAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, cus: execution of AfterUpdate
caused by: System.NullPointerException: Argument cannot be null
Trigger.cus: line 10, column 1: [] 
Stack Trace Class.Testcus.testingCus: line 40, column 1 
trigger

trigger cus on Sample_Transaction__c(after update) {
    Call2__c Objopp;
    Map<Id,Sample_Transaction__c> o = new Map<Id,Sample_Transaction__c>();
    o = trigger.oldMap;
    
        for (Sample_Transaction__c objCustomer: Trigger.new) {
       if (objCustomer.Status__c== 'Active') {
       if(objCustomer.Status__c!= o.get(objCustomer.Id).Status__c) {
       List<String> s = new List<String>{objCustomer.Call_ID__c};
        ApexPages.StandardController controller = new ApexPages.standardController(Objopp);
     UnlockRecordDuringApprovalCon ObjUnlock= new UnlockRecordDuringApprovalCon(controller);
                      for(Call2__c c: [SELECT id FROM Call2__c WHERE Name IN :s]){
                                     ObjUnlock.processRecord(c.id );
               
            }
       }
    }
 }
   }




test class


@isTest
private class Testcus {
    static testMethod void testingCus(){

Account TestOpp=new Account();
        TestOpp.Name='Testopp1';
        TestOpp.SLN__c='asdfc45';
        insert TestOpp;
        
        Call2__c Testcall =new Call2__c();
        Testcall.Account__c=TestOpp.id;
        insert Testcall ;
        
        Address__c testadd = new Address__c();
        testadd.Name='aaa';
        testadd.Account__c=TestOpp.id;
        insert testadd;

        Sample_Lot__c testsample=new Sample_Lot__c();

        testsample.Name='aaa';
          insert  testsample;
        
        Product__c testprod = new Product__c();
        testprod.Name='aaa';
        insert testprod;
        
            Sample_Transaction__c testapp1 = new Sample_Transaction__c();
           testapp1.Account_ID__c =TestOpp.id;
            
        
       testapp1.Address_ID__c= testadd.id;
       testapp1.Sample_Lot_ID__c=testsample.id;
testapp1.Product__c= testprod.id;

insert testapp1;
        
        
        testapp1.Status__c = 'Saved';
        update testapp1 ;
    }
}


 
how to write test class for below trigger for oldmap please advise me

trigger cus on Sample_Transaction__c(before update) {
    Call2__c Objopp;
    Map<Id,Sample_Transaction__c> o = new Map<Id,Sample_Transaction__c>();
    o = trigger.oldMap;
     ApexPages.StandardController controller = new ApexPages.standardController(Objopp);
     UnlockRecordDuringApprovalCon ObjUnlock= new UnlockRecordDuringApprovalCon(controller);
        for (Sample_Transaction__c objCustomer: Trigger.new) {
       if (objCustomer.Status__c== 'Active') {
       if(objCustomer.Status__c!= o.get(objCustomer.Id).Status__c) {
       List<String> s = new List<String>{objCustomer.Call_ID__c};
                      for(Call2__c c: [SELECT id FROM Call2__c WHERE Name IN :s]){
                                     ObjUnlock.processRecord(c.id );
               
            }
       }
    }
 }
   }
i a object called call and another object called transaction , this transaction is related to call , i would like to update a field in transaction when the call is submitted how to do it ? which is the best method. the reason i want to update is i want to invoke a trigger at transaction  when the call is submitted . i dont want to write trigger in call object . once i update the field in when call is submitted then trigger will invoke in transaction
please advise me  
I have a parent object and child object and am updating the sum of child records to a field in parent
do my below code cover governor limit please advise. 
trigger quantityleft on Sample_Transaction__c (after insert,after update,after delete,after undelete) {
    List<Sample_Lot__c> list_Account= new List<Sample_Lot__c>();
    set<Id> set_Opportunity = new set<Id>();
     if(Trigger.isInsert || Trigger.isUndelete){
        for(Sample_Transaction__c objOpp: trigger.new){
        
        if(objOpp.Completed_Transaction__c == true){
         set_Opportunity.add(objOpp.Parent_id__c);
           }
    }
    }
    
    if(Trigger.isUpdate){
        for(Sample_Transaction__c objOpp: trigger.new){
        
        if(objOpp.Completed_Transaction__c == true){
         set_Opportunity.add(objOpp.Parent_id__c);
           }
  }
    
    
    }
    
    if(Trigger.isdelete){
        for(Sample_Transaction__c objOpp: trigger.old){
        
        if(objOpp.Completed_Transaction__c == true){
         set_Opportunity.add(objOpp.Parent_id__c);
           }
  
    }
    
    }

    if(!set_Opportunity.isEmpty()){
    
    
    
                 Decimal Sum;
       Sum=0;

  for(Sample_Transaction__c sample_transaction : [SELECT id,Sample_Lot_ID__c, Transaction_Quantity__c FROM Sample_Transaction__c WHERE Parent_id__c = : set_Opportunity

]){
            
            Sum+= sample_transaction.Transaction_Quantity__c;
  
    
    for(Sample_Lot__c objAccount : [SELECT Id, Quantity_Left__c FROM Sample_Lot__c WHERE Id = : sample_transaction.Sample_Lot_ID__c]){

 

            objAccount.Quantity_left__c = Sum ;

            list_Account.add(objAccount);

 update objAccount ;

        }
        
 }
}

    
}

 
In below code am getting , am trying so many different method sample lot is parent and sample transaction is child could you please suggets me what is the reason for below error
Compile Error: Didn't understand relationship 'Sample_Transaction__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 44

 
trigger quantityleft on Sample_Transaction__c (after insert,after update,after delete,after undelete) {
    List<Sample_Lot__c> list_Account= new List<Sample_Lot__c>();
     set<Id> set_Opportunity = new set<Id>();
         for(Sample_Transaction__c objOpp: trigger.new){
        set_Opportunity.add(objOpp.Sample_Lot_ID__c);
    }
    Decimal Sum;
            for(Sample_Lot__c objAccount : [SELECT Id,(SELECT Id,sample_lot FROM Sample_Transaction__c),Quantity_Left__c FROM Sample_Lot__c WHERE Id IN: set_Opportunity]){
        Sum=0;
                        
        for(Sample_Transaction__c objOpp01: objAccount.Quantity_Left__c){
            Sum+=objOpp01.Confirmed_Quantity__c ;
        }
        objAccount.Quantity_left__c =Sum;
        list_Account.add(objAccount);
    }
    update list_Account;
}

 
I have a reuiqrement i want to have a field in parent record and get the sum of a field from all child record. this is lookup relationship record. how to do in a easy way , please suggest me.