• Ajith MD
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
Im getting error like Nan during subtraction of two times. Can anyone help me how to resolve this?

var startDate = component.get("v.time");
        var endDate = component.get("v.time1");
        var days = (endDate-startDate)/8.64;
        alert(days);

please say me how to find difference between two times not two days
I'm new to salesforce, Is there any way to use a Custom Label in URL
https://developer--uat.lightning.force.com/lightning/r/Report/00O0w000000ZLryEAG/view?fv0={!Service_Provider__c.Name}
Instead of https://developer--uat.lightning.force.com/lightning/r/Report
how to use custom labels here ..! Thanks in Advance.
Im getting null.exception while save record on Sales__c. And the child record is also not created on Recurring__c. Can anyone help me to resolve this. 
trigger Grossamount on Sales__c ( before insert, before update, after insert) {
    if( Trigger.isUpdate || Trigger.isInsert) {
        for(Sales__c t: Trigger.new){
            if(t.Type__c == 'One Time' ){
                t.Gross_Amount__c = t.Amount__c;
            } 
            else if(t.Type__c == 'Recurring' ){
                t.Amount_Recurring__c = t.Amount__c * t.Term__c;
                t.Gross_Amount__c = t.Amount_Recurring__c;
                Date new1= t.Sale_Date__c;
                if(t.Frequency__c== 'Weekly'){
                    for(integer i =0; i < t.Term__c; i++){  
                        Recurring__c child = new Recurring__c();
                        child.Sales__c = t.Id;
                        System.debug(child.Sales__c);
                        child.Name = t.Name;
                        child.Amount__c= t.Amount__c;
                        child.Due_Date__c = new1;
                        Date new2 = new1.addDays(7);
                        new1 = new2;    
                        System.debug('Hi');
                        insert child; 
                    } 
                }
                else if(t.Frequency__c == 'Monthly'){
                    for(integer i =0; i < t.Term__c; i++){  
                        Recurring__c child = new Recurring__c();
                        child.Sales__c = t.Id;
                        System.debug(child.Sales__c);
                        child.Name = t.Name;
                        child.Amount__c= t.Amount__c;
                        child.Due_Date__c = new1;
                        Date new2 = new1.addMonths(1);
                        new1 = new2;    
                        System.debug('Hi');
                        insert child; 
                    } 
                }
                else if(t.Frequency__c == 'Quarterly'){
                    for(integer i =0; i < t.Term__c; i++){  
                        Recurring__c child = new Recurring__c();
                        child.Sales__c = t.Id;
                        System.debug(child.Sales__c);
                        child.Name = t.Name;
                        child.Amount__c= t.Amount__c;
                        child.Due_Date__c = new1;
                        Date new2 = new1.addMonths(4);
                        new1 = new2;    
                        System.debug('Hi');
                        insert child; 
                    } 
                }
                else {
                    for(integer i =0; i < t.Term__c; i++){  
                        Recurring__c child = new Recurring__c();
                        child.Sales__c = t.Id;
                        System.debug(child.Sales__c);
                        child.Name = t.Name;
                        child.Amount__c= t.Amount__c;
                        child.Due_Date__c = new1;
                        Date new2 = new1.addMonths(12);
                        new1 = new2;    
                        System.debug('Hi');
                        insert child; 
                    } 
                }
            }
            
            else {
                t.Amount_Service__c = t.Amount__c;
                t.Gross_Amount__c = t.Amount_Service__c;
            }
        }
        
    } 
}
My code is trigger duplicateaccount on Account (before insert, after insert) {
  
    List<Account> st = new List<Account>();
    st = [SELECT CreatedDate FROM Account ORDER BY CreatedDate DESC NULLS LAST LIMIT 1];
    for(Account a: Trigger.new){
        
    for(Account acc:st){
        System.debug('createddate' + acc.CreatedDate);
        Datetime firsttime = System.now();
        System.debug('first time' + firsttime);
        Datetime secondtime = Datetime.valueOf(acc.CreatedDate);
        System.debug('Secondtime' + secondtime);
        Decimal millisecondsBetween = firstTime.getTime() - secondTime.getTime();
        System.debug(millisecondsBetween);
        Decimal timeBetween = millisecondsBetween / 3600000; 
        decimal timediff = timeBetween.setscale(0);
        System.debug('diif'+timediff);
        
        if(timediff > 1) {    
            for(Account temp: st){
                Account objAccount = Trigger.newMap.get(temp.id);
                objAccount.addError('one hour');            
            }
            
        }
    }
    }

}

Can anyone help me how to resolve this.
Im getting error like Nan during subtraction of two times. Can anyone help me how to resolve this?

var startDate = component.get("v.time");
        var endDate = component.get("v.time1");
        var days = (endDate-startDate)/8.64;
        alert(days);

please say me how to find difference between two times not two days
Im getting null.exception while save record on Sales__c. And the child record is also not created on Recurring__c. Can anyone help me to resolve this. 
trigger Grossamount on Sales__c ( before insert, before update, after insert) {
    if( Trigger.isUpdate || Trigger.isInsert) {
        for(Sales__c t: Trigger.new){
            if(t.Type__c == 'One Time' ){
                t.Gross_Amount__c = t.Amount__c;
            } 
            else if(t.Type__c == 'Recurring' ){
                t.Amount_Recurring__c = t.Amount__c * t.Term__c;
                t.Gross_Amount__c = t.Amount_Recurring__c;
                Date new1= t.Sale_Date__c;
                if(t.Frequency__c== 'Weekly'){
                    for(integer i =0; i < t.Term__c; i++){  
                        Recurring__c child = new Recurring__c();
                        child.Sales__c = t.Id;
                        System.debug(child.Sales__c);
                        child.Name = t.Name;
                        child.Amount__c= t.Amount__c;
                        child.Due_Date__c = new1;
                        Date new2 = new1.addDays(7);
                        new1 = new2;    
                        System.debug('Hi');
                        insert child; 
                    } 
                }
                else if(t.Frequency__c == 'Monthly'){
                    for(integer i =0; i < t.Term__c; i++){  
                        Recurring__c child = new Recurring__c();
                        child.Sales__c = t.Id;
                        System.debug(child.Sales__c);
                        child.Name = t.Name;
                        child.Amount__c= t.Amount__c;
                        child.Due_Date__c = new1;
                        Date new2 = new1.addMonths(1);
                        new1 = new2;    
                        System.debug('Hi');
                        insert child; 
                    } 
                }
                else if(t.Frequency__c == 'Quarterly'){
                    for(integer i =0; i < t.Term__c; i++){  
                        Recurring__c child = new Recurring__c();
                        child.Sales__c = t.Id;
                        System.debug(child.Sales__c);
                        child.Name = t.Name;
                        child.Amount__c= t.Amount__c;
                        child.Due_Date__c = new1;
                        Date new2 = new1.addMonths(4);
                        new1 = new2;    
                        System.debug('Hi');
                        insert child; 
                    } 
                }
                else {
                    for(integer i =0; i < t.Term__c; i++){  
                        Recurring__c child = new Recurring__c();
                        child.Sales__c = t.Id;
                        System.debug(child.Sales__c);
                        child.Name = t.Name;
                        child.Amount__c= t.Amount__c;
                        child.Due_Date__c = new1;
                        Date new2 = new1.addMonths(12);
                        new1 = new2;    
                        System.debug('Hi');
                        insert child; 
                    } 
                }
            }
            
            else {
                t.Amount_Service__c = t.Amount__c;
                t.Gross_Amount__c = t.Amount_Service__c;
            }
        }
        
    } 
}

Hi,

 

I am finding accumulated sum in some objects.My logic is worked in some objects.In some other objects the following error is raising.

 

Review all error messages below to correct your data.
Apex trigger chiranjeevi.mbltotal caused an unexpected exception, contact your administrator: chiranjeevi.mbltotal: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.chiranjeevi.mbltotal: line 10, column 15

 

my code is as follows:

 

trigger mbltotal on chiranjeevi__Sea_Foot_Note__c (before insert,before update) {
Double objBtotal = 0;
List<chiranjeevi__Master_Bill_Of_Ladding__c> objAlist=new List<chiranjeevi__Master_Bill_Of_Ladding__c>();
for(chiranjeevi__Sea_Foot_Note__c b : Trigger.new)
objAlist=[SELECT chiranjeevi__Console_charges__c,chiranjeevi__SFN_no__c FROM chiranjeevi__Master_Bill_Of_Ladding__c Where chiranjeevi__SFN_no__c =: b.Id];
for (chiranjeevi__Sea_Foot_Note__c objA : Trigger.new)
{
for (chiranjeevi__Master_Bill_Of_Ladding__c objB : objAlist)

 objBtotal += objB.chiranjeevi__Console_charges__c;
   objA.chiranjeevi__Total_service_charges__c=objBtotal;

}    
}


If any one find out the solution plz help me.

 

Thanks in advance,

Anu..