• Kalyan Ranjan
  • NEWBIE
  • 5 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi, 

I am working on an LWC mini-project "Airline Ticket Booking". I want a button by which the user can add as many passengers as he wants for the purpose of ticket booking. How it would be possible? Please give me an appropriate link so that I can learn.
Hi getting error when trying to delete a recourd wher record owner != logged in user below is my code 

trigger MobDiscount on Mobile__c (before insert,before update,before delete) {
Trigger :     
    if(Trigger.isinsert == true)
    {
        DiscountForMobiles.DiscountNewCoustomer(Trigger.new);
    }
    
    if(Trigger.isupdate == true)
    {
        DiscountForMobiles.DiscountOldCoustomer(Trigger.new);
    }
    
    if(Trigger.isdelete == true && Trigger.isbefore == true)
    {
        DiscountForMobiles.OwnwerAloneCanDelete(Trigger.old);
    }
    
}

Apex Class :

public class DiscountForMobiles {
    
    Public Static Void DiscountNewCoustomer(List<Mobile__c> CoustomerList)
    {
        for(Mobile__c SingleCoustomer : CoustomerList ){
            
            If(SingleCoustomer.Brand__c == 'Samsung')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c * 10/100;
               SingleCoustomer.Discount_Status__c = '10 % Discount';
            }
            
            if(SingleCoustomer.Brand__c == 'Apple')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c - SingleCoustomer.Price__c * 5/100;
               SingleCoustomer.Discount_Status__c = '5 % Discount';
            }
            
        }
        
    }

    Public Static Void DiscountOldCoustomer(List<Mobile__c> CoustomerList)
    {
        for(Mobile__c SingleCoustomer : CoustomerList ){
            
            If(SingleCoustomer.Brand__c == 'Samsung')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c - SingleCoustomer.Price__c * 10/100;
               SingleCoustomer.Discount_Status__c = '5 % Discount';
            }
            
            If(SingleCoustomer.Brand__c == 'Apple')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c * 5/100;
               SingleCoustomer.Discount_Status__c = 'NO Discount';
            }
            
        }
        
    }
    Public Static Void OwnwerAloneCanDelete(List<Mobile__c> CoustomerList)
    {
        
        for(Mobile__c Costomer : CoustomerList)
        {
            If(Costomer.OwnerId != Userinfo.getUserId())
            {
                Costomer.adderror('only owner can delete');
            }
        }
         
    }
      
}