• Prerna Raj 7
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
I am learning on plural site from David Liu's course he gave this code to create a child case when ever the parent has sensitive information. the code worked for him but when i tried creating a case with the sensitive information in salesforce, the child case wasn't created.

pasting my code below...
trigger CheckSecretInformation on Case (after insert, before update) {
        
    String childcaseSubject = 'Warning: Parent may contain Secret Info';
    
    //Create a collection of each of our secret keywords
    Set<String> Keywords = new Set<string>();
            keywords.add('SSN');
            Keywords.add('Social Seccurity');
            keywords.add('Credit Card');
            keywords.add('Passport');
            Keywords.add('BodyWeight');
             
     
    //Checking if the case description contains any of the secret keywords
    List<Case> casesWithKeywords = new List<Case>();
    for (case myCase : Trigger.New){
        if (mycase.Subject != childcaseSubject){    
        for (string keyword : keywords){
            if (myCase.Description != null && myCase.Description.containsIgnoreCase(keyword)){
                casesWithKeywords.add(myCase);
               system.debug('Case' + myCase.Id + 'include keyword' + keyword);
                break;
              }
            
            }
               
        }
    }  
    
        //Create a child case, if the decriptio contains secret keywords
    for(case caseWithKeywords : casesWithKeywords){
        Case childCase             = new Case();
        childCase.subject         = childcaseSubject;
        childcase.ParentId        = caseWithKeywords.Id;
        childCase.isEscalated    = True;
        childCase.Priority      = 'High';
        childCase.Description     = 'Atlest one of the following keywords were found' + keywords;
        insert childCase;
            
    }
    }
 
I am new to coding and am still learning. I am getting the error for  "variable does not exist : i " in my code below -   I have made the 2 lines in which i am getting the error bold

trigger LeadingCompetitor on Opportunity (before insert, before update) {
    
    for (Opportunity opp : Trigger.new){
        //Add all prices to our list in order of competitors
            List<Decimal> competitorPrices = New List<Decimal>();
            competitorPrices.add(opp.Competitor_1_Price__c);
            competitorPrices.add(opp.Competitor_2_Price__c);
            competitorPrices.add(opp.Competitor_3_Price__c);
       
        //Add all competitors to our list in order 
            List<String> competitorName = New List<String>();
            competitorName.add(opp.Competitor_1__c);
            competitorName.add(opp.Competitor_2__c);
            competitorName.add(opp.Competitor_3__c);
        
        //Loop throughall competitors to find the position of the lowest price
            Decimal lowestPrice;
            Integer lowestPricePosition;
        
            for (Integer i = 0; i < competitorPrices.size(); i++); {
                Decimal currentPrice = competitorPrices.get(i);
                if(lowestPrice == Null || currentPrice < lowestPrice) {
                    lowestPrice = currentPrice;
                     lowestPricePosition = i;
            }
            }
        //Populate the leading competitor field with the competitor matching the lowest price position
                   opp.Leading_Competitor__c = competitorName.get(lowestPricePosition);
                
    
    }    
}
I am new to coding and am still learning. I am getting the error for  "variable does not exist : i " in my code below -   I have made the 2 lines in which i am getting the error bold

trigger LeadingCompetitor on Opportunity (before insert, before update) {
    
    for (Opportunity opp : Trigger.new){
        //Add all prices to our list in order of competitors
            List<Decimal> competitorPrices = New List<Decimal>();
            competitorPrices.add(opp.Competitor_1_Price__c);
            competitorPrices.add(opp.Competitor_2_Price__c);
            competitorPrices.add(opp.Competitor_3_Price__c);
       
        //Add all competitors to our list in order 
            List<String> competitorName = New List<String>();
            competitorName.add(opp.Competitor_1__c);
            competitorName.add(opp.Competitor_2__c);
            competitorName.add(opp.Competitor_3__c);
        
        //Loop throughall competitors to find the position of the lowest price
            Decimal lowestPrice;
            Integer lowestPricePosition;
        
            for (Integer i = 0; i < competitorPrices.size(); i++); {
                Decimal currentPrice = competitorPrices.get(i);
                if(lowestPrice == Null || currentPrice < lowestPrice) {
                    lowestPrice = currentPrice;
                     lowestPricePosition = i;
            }
            }
        //Populate the leading competitor field with the competitor matching the lowest price position
                   opp.Leading_Competitor__c = competitorName.get(lowestPricePosition);
                
    
    }    
}