• Porty 23110
  • NEWBIE
  • 65 Points
  • Member since 2018

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 12
    Replies
I've been doing David Liu's excellent Apex Academy courses to try and get introduced to Apex coding. But he uses MavensMate as his editor, which has now been dropped.

Using the built in Salesforce Developer Console, I get tonnes of errors. I've gone through and doubled checked all my code and I am pretty confident it is correct.

So what is causing all of these errors???

Price Wars demo

and here is my code:

trigger LeadingCompetitor on Opportunity (before insert, before update) {
    
    for (Opportunity opp : Trigger.new) {
        // all of our prices in a list in order of competitor
        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 of our competitors in a list in the same order
        List<String> competitors = List<String>();
        competitors.add(opp Competitor_1__c);
        competitors.add(opp Competitor_2__c);
        competitors.add(opp Competitor_3__c);
        
        //  loop through all the competitors to find the position of the lowest price
        Decimal lowestPrice;
        Integer lowestPricePosition;
        for (Interger 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 = competitors.get(lowestPricePosition);
    }

}
I have a trigger that prompts the user to include an attachment before saving a case record. Can someone please help me with the test class that provides a 100% code coverage. 
trigger CaseAttachment on Case (before update) {
    
    for (Case myCase : Trigger.New) {
        if (myCase.Status == 'Repair Confirmed') {
            
            Attachment myAttachment = new Attachment();
            
            try {
                myAttachment = [Select Id, Name from Attachment where ParentId = :myCase.Id];
            }
         
            catch (Exception e)  {
                myAttachment = null;
            } 
                
                
                if (myAttachment ==null)
                    myCase.addError ('Add picture to the record');
                
                
            }
            
            
                
        }
        
        
    }
trigger OpportunitiesCreateonAccount on Account (after insert) {
    for (Account acc :Trigger.new) {
        for (Integer i = i <  11 (); i++)  {
          if (acc.NumberofEmployees > 99) {
              
      List<Opportunity> newOpportunity = new List<Opportunity>();
              
            Opportunity opp = new Opportunity();
            opp.Name = acc.Name + i;
            opp.AccountId = acc.Id;
            opp.StageName = 'Prospecting';
            opp.CloseDate = Date.today();
              newOpportunity.add(opp);
              insert newOpportunity;
            
            
            
            
            
            
        }
        
        }
        
    }
}

I want to write a trigger that creates 10 opportunity records when an account with employees greater than 99 is created.  I keep getting problem on this code. Any help will be appreciated.
I have the following scenario. I want to populate the highest price and the name of the company with the highest price. The name of the competitor populate but i am struggling to populate the corresponding price. Code below;

trigger LeadingCompetitor on Opportunity (before insert, before update) {
    for (Opportunity opp :Trigger.new) {
        List <Decimal> competitorPrice = new List <Decimal> ();
        
        //Add all of our prices in a list in order of competitor
        competitorPrice.add (opp.Competitor_1_Price__c);
        competitorPrice.add (opp.Competitor_2_Price__c);
        competitorPrice.add (opp.Competitor_3_Price__c);
        
        //Add all our competitors in a list in order
        
        List <String> competitors = new List <string> ();
        competitors.add (opp.Competitor_1__c);
        competitors.add (opp.Competitor_2__c);
        competitors.add (opp.Competitor_3__c);
        
        //Loop through all the competitor to find the highest price
        
        Decimal highestPrice;
        Integer highestPricePosition;
        for (Integer i = 0; i > competitorPrice.size();i++) {
            Decimal currentPrice = competitorPrice.get(i);
            if (highestPrice == null || currentPrice > highestPrice) {
          
                
                highestPrice = currentPrice;
                highestPricePosition = i;
            }
            
            
        }
        
        //Populate the leading competitor with the competitor matching the highest price position& populate the corresponding price of the competitor
        opp.Leading_Competitor__c = competitors.get(highestPricePosition);
        opp.Leading_Competitor_Price__c = competitorPrice.get (highestPricePosition);
        
    }

}
 
I'm new to apex and currently learning variables and trigger. I'm creating simple scenarios and attempting to write triggers for those scenarios. Below are the 2 scenarios I need help with;

Write a trigger that creates a contact when an account is created and should be associated with the account.

Write a trigger that creates two identical Contacts whenever an account is created and should be associated with the account.

Here's the trigger I wrote for the first scenario and I get an error when I try to create a new account. 
How do I go about the second trigger?

trigger AccountCreate on Account (after insert) {
    
    for (Account acc : Trigger.new) {
    
    Contact C = new Contact();
    
    C.LastName = 'Grace';
    C.AccountId = acc.id;
    C.Email = 'testme@hotmail.com';
 
    insert acc;
      }
}
 
I have a trigger that prompts the user to include an attachment before saving a case record. Can someone please help me with the test class that provides a 100% code coverage. 
trigger CaseAttachment on Case (before update) {
    
    for (Case myCase : Trigger.New) {
        if (myCase.Status == 'Repair Confirmed') {
            
            Attachment myAttachment = new Attachment();
            
            try {
                myAttachment = [Select Id, Name from Attachment where ParentId = :myCase.Id];
            }
         
            catch (Exception e)  {
                myAttachment = null;
            } 
                
                
                if (myAttachment ==null)
                    myCase.addError ('Add picture to the record');
                
                
            }
            
            
                
        }
        
        
    }
trigger OpportunitiesCreateonAccount on Account (after insert) {
    for (Account acc :Trigger.new) {
        for (Integer i = i <  11 (); i++)  {
          if (acc.NumberofEmployees > 99) {
              
      List<Opportunity> newOpportunity = new List<Opportunity>();
              
            Opportunity opp = new Opportunity();
            opp.Name = acc.Name + i;
            opp.AccountId = acc.Id;
            opp.StageName = 'Prospecting';
            opp.CloseDate = Date.today();
              newOpportunity.add(opp);
              insert newOpportunity;
            
            
            
            
            
            
        }
        
        }
        
    }
}

I want to write a trigger that creates 10 opportunity records when an account with employees greater than 99 is created.  I keep getting problem on this code. Any help will be appreciated.
I have the following scenario. I want to populate the highest price and the name of the company with the highest price. The name of the competitor populate but i am struggling to populate the corresponding price. Code below;

trigger LeadingCompetitor on Opportunity (before insert, before update) {
    for (Opportunity opp :Trigger.new) {
        List <Decimal> competitorPrice = new List <Decimal> ();
        
        //Add all of our prices in a list in order of competitor
        competitorPrice.add (opp.Competitor_1_Price__c);
        competitorPrice.add (opp.Competitor_2_Price__c);
        competitorPrice.add (opp.Competitor_3_Price__c);
        
        //Add all our competitors in a list in order
        
        List <String> competitors = new List <string> ();
        competitors.add (opp.Competitor_1__c);
        competitors.add (opp.Competitor_2__c);
        competitors.add (opp.Competitor_3__c);
        
        //Loop through all the competitor to find the highest price
        
        Decimal highestPrice;
        Integer highestPricePosition;
        for (Integer i = 0; i > competitorPrice.size();i++) {
            Decimal currentPrice = competitorPrice.get(i);
            if (highestPrice == null || currentPrice > highestPrice) {
          
                
                highestPrice = currentPrice;
                highestPricePosition = i;
            }
            
            
        }
        
        //Populate the leading competitor with the competitor matching the highest price position& populate the corresponding price of the competitor
        opp.Leading_Competitor__c = competitors.get(highestPricePosition);
        opp.Leading_Competitor_Price__c = competitorPrice.get (highestPricePosition);
        
    }

}
 
I'm new to apex and currently learning variables and trigger. I'm creating simple scenarios and attempting to write triggers for those scenarios. Below are the 2 scenarios I need help with;

Write a trigger that creates a contact when an account is created and should be associated with the account.

Write a trigger that creates two identical Contacts whenever an account is created and should be associated with the account.

Here's the trigger I wrote for the first scenario and I get an error when I try to create a new account. 
How do I go about the second trigger?

trigger AccountCreate on Account (after insert) {
    
    for (Account acc : Trigger.new) {
    
    Contact C = new Contact();
    
    C.LastName = 'Grace';
    C.AccountId = acc.id;
    C.Email = 'testme@hotmail.com';
 
    insert acc;
      }
}
 
I've been doing David Liu's excellent Apex Academy courses to try and get introduced to Apex coding. But he uses MavensMate as his editor, which has now been dropped.

Using the built in Salesforce Developer Console, I get tonnes of errors. I've gone through and doubled checked all my code and I am pretty confident it is correct.

So what is causing all of these errors???

Price Wars demo

and here is my code:

trigger LeadingCompetitor on Opportunity (before insert, before update) {
    
    for (Opportunity opp : Trigger.new) {
        // all of our prices in a list in order of competitor
        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 of our competitors in a list in the same order
        List<String> competitors = List<String>();
        competitors.add(opp Competitor_1__c);
        competitors.add(opp Competitor_2__c);
        competitors.add(opp Competitor_3__c);
        
        //  loop through all the competitors to find the position of the lowest price
        Decimal lowestPrice;
        Integer lowestPricePosition;
        for (Interger 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 = competitors.get(lowestPricePosition);
    }

}
I am having a hard time getting past the Admin Intermediate "Guide Users Through Your Business Processes with Cloud Flow Designer " Challenge. I keep getting the error: Challenge Not yet complete... here's what's wrong:  Can't find the forceContent:fileUpload Lightning component in the 'New Lead' flow. Make sure the field’s unique name is 'Upload_File'

I've followed all of the directions exactly, get no errors when i'm building the flow and i've tried three different playgrounds and have cleared browser/history and restarted my browser between each one. I can't seem to get past this issue
User-added image