• Jennifer Laing
  • NEWBIE
  • 45 Points
  • Member since 2014
  • Salesforce Business Consultant
  • Wood Mackenzie


  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 15
    Replies
Hello

Does anyone know how I could update a Contact Status field to the custom value of "Opportunity" when a new Opportunity is created then update the Status again when the Opportunity is closed?  Note, the Org is Professional Edition so I can't use Workflow Rules for this and I have no experience/knowledge of Triggers.

Any help would be appreciated!
Hello

I am trying to add a custom Lightning link to an Opportunity record.  The link successfully opens the custom object record page however, I need the Account Name and Opportunity Name to be autopopulated.  How can I achieve this in the formula?  This is the formula I currently have - which does not autopopulate the fields:

/one/one.app#/alohaRedirect/a1H/e?
&{!$Setup.Request_Fields__c.Account_name__c}"_lkid="{!Account.Id}
&"retURL=%2F"{!Opportunity.Id}
&{!$Setup.Request_Fields__c.Opportunity_name__c}"="{!Opportunity.Name}
&{!$Setup.Request_Fields__c.Opportunity_name__c}"_lkid="{!Opportunity.Id}
&"RecordType="{!$Setup.RecordTypeID__c.Request_Credit_Check__c}
Hello

I'm hoping someone can help me write a Test Class for this Trigger please?  I have attempted it (first time!) but am having issues with the "insert" line/element (note, the ID's are false ID's for this example):

Test Class:

@isTest 
public class ChildAccountOwnerUpdate {
        static testMethod void ParentChildOwner()   {
        
        Account a = new Account();
        a.Name ='Test Account' ;
        a.ParentId = '0018E00000glxyz';
        a.OwnerId = '005D0000007dxyz';    
        insert ;
       
            }

}

Trigger:

Trigger ParentChildOwner on Account (Before Insert, Before Update, After UnDelete) {
02     
03    List<Account> comingAccounts      = New List<Account>();
04    List<Id> comingAccountsParentIds  = New List<Id>();
05     
06    If(Trigger.IsInsert || Trigger.IsUpdate || Trigger.IsUnDelete){
07        For(Account act : Trigger.New)
08        {
09            If(act.ParentId != NULL)
10            {
11               comingAccounts.add(act);
12               comingAccountsParentIds.add(act.ParentId);
13            }
14             
15        }
16    }
17     
18    List<Account> fetchingParentAccount = [Select Id, OwnerID FROM Account WHERE Id=:comingAccountsParentIds AND OwnerID != NULL];
19    //system.debug('The size of fetchingParentAccount is: ' + fetchingParentAccount.size());
20     
21    For(Account EveryAct : comingAccounts)
22    {
23        //system.debug('EveryAct existing owner id is: ' + EveryAct.OwnerId);
24         
25        For(Account EveryParent : fetchingParentAccount)
26        {
27            If(EveryAct.ParentId == EveryParent.Id)
28            {
29                EveryAct.OwnerId = EveryParent.OwnerId;
30            }
31        }
32         
33        //system.debug('EveryAct new owner id is: ' + EveryAct.OwnerId);
34    }
35}
I have never created a Trigger before but I believe when I'm trying to achieve is (relatively!) simple?!  I would like new Child Account Record Owners to have the same owner as the Parent Account Record Owner when the Child is created.  Is this possible?
Hello

I have successfully installed the Know Your Enemy App from AppExchange by Salesforce Labs however, the News and Twitter Feeds don't work.  These are Visualforce pages.  Does anyone know how I can fix this?  

Many thanks in advance.
Hello

I'm hoping someone can help me as I have very little developer experience!

I'm receiving the Too many SOQL queries: 101 error.  The code is below.  Can someone please advise how I can fix this?  Any help would be greatly appreciated!  I've removed most of the commented out statements.

trigger OpportunityLineItemTrigger on OpportunityLineItem (after delete, before insert, after insert, before update,after update) {
    
    if(Trigger.isAfter){
        if(Trigger.isDelete){
            // Flag opps having OLIs with different end dates
            OpportunityLineItemTriggerMethods.checkLineItemEndDates(trigger.old);

            //delete related RevenueScheduleItems
            OpportunityLineItemTriggerMethods.removeRevenueScheduleItems(trigger.old);
            
            // Create Deleted_OpportunityLineItem objects, for the Cast Iron integration.
            OpportunityLineItemTriggerMethods.createDeletedLineItemObjects(trigger.old);
            

        }else if(Trigger.isUpdate){
            //copy the modified fields from OLI to related RSI records
            OpportunityLineItemTriggerMethods.updateRevenueScheduleItems(trigger.newMap,trigger.oldMap);
            
            // Add any new revenue schedule items, if the term is increased and it's a closed consulting opportunity line item.
            OpportunityLineItemTriggerMethods.createAdditionalRevenueScheduleItems(trigger.new, trigger.oldMap);
        }
    }   
    
    if(Trigger.isBefore && (Trigger.isInsert || Trigger.isUpdate)){
        
        
        OpportunityLineItemTriggerMethods.opportunityLineItemExchangeRateStamping(Trigger.new, Trigger.oldMap);
          
        OpportunityLineItemTriggerMethods.calculatePPLTotalPrice(Trigger.isInsert, Trigger.new, Trigger.oldMap);
        for(OpportunityLineItem oli:Trigger.New)
        {
          
            Double upLift = oli.Uplift_Percentage__c == null ? 0.0 : oli.Uplift_Percentage__c;
            Double term = oli.term__c == null ? 0.0 : oli.term__c;
            
            Double multiplier = (1.0 + (upLift/100)) * term * 
                    (oli.Company_type_factor__c == null || oli.Company_type_factor__c == 0.0 ? 1.0 : oli.Company_type_factor__c) *
                    (oli.Company_size_factor__c == null || oli.Company_size_factor__c == 0.0 ? 1.0 : oli.Company_size_factor__c);
            Double ppm = oli.Previous_Price_Per_Month__c == null ? 0.0 : oli.Previous_Price_Per_Month__c;
            Double listPrice = oli.ListPrice == null ? 0.0 : oli.ListPrice;
            Double researchAmount = oli.Research_Amount_Price__c == null ? 0.0 : oli.Research_Amount_Price__c;
            Double scheduledDiscount = oli.Scheduled_Discount__c == null ? 0.0 : oli.Scheduled_Discount__c;
            Double unitPrice = oli.UnitPrice == null ? 0.0 : oli.UnitPrice;
            
            oli.Research_Amount_Price__c = (ppm == 0.0) ? (listPrice / 12) * multiplier :ppm * multiplier;
            Double researchAmount1 = oli.Research_Amount_Price__c;
            oli.Discount_Gap__c = (listPrice == 0) ? 0 : researchAmount1 * (1-(scheduledDiscount/100)) - unitPrice; 
        }
    }
    
      if(Trigger.isBefore && Trigger.isInsert){ 
        OpportunityLineItemTriggerMethods.defaultStartDate(Trigger.new);
    }
    
    // 15/06/2012 DP Update
    if (Trigger.isAfter && Trigger.isInsert) {
        OpportunityLineItemTriggerMethods.createRevenueScheduleItems(Trigger.new);
    }
    
    if(Trigger.isAfter ){
        // automatically apply scheduled discounts 
        // future methods can't take sObject arguments .
        OpportunityLineItemTriggerMethods.checkScheduledDiscounts(trigger.new,trigger.oldMap);
        
        // Flag opps having OLIs with different end dates
        if (!Trigger.isDelete){
            OpportunityLineItemTriggerMethods.checkLineItemEndDates(trigger.new);       
        }
    }
    
}
Hi, sorry to re-start this conversation, but I'm having similar problems to Andrew Eversley with regards to creating the visual workflow in the Trailhead Challenge. Can anyone advise where I'm going wrong please?

The error message is: 
caused by element : FlowRecordCreate.Opportunity_Create
caused by: UPSERT --- UPSERT FAILED --- ERRORS : (REQUIRED_FIELD_MISSING) Required fields are missing: [StageName] --- for SFDC record with ID : null,  

User-added image
User-added image
User-added image
User-added image
User-added image
I'm new to the developer side of Salesforce and was hoping someone could give me guidance on creating a Workflow rule to alert the Ideas creator when a new Comment has been added?  Many thanks in advance.
Hi, sorry to re-start this conversation, but I'm having similar problems to Andrew Eversley with regards to creating the visual workflow in the Trailhead Challenge. Can anyone advise where I'm going wrong please?

The error message is: 
caused by element : FlowRecordCreate.Opportunity_Create
caused by: UPSERT --- UPSERT FAILED --- ERRORS : (REQUIRED_FIELD_MISSING) Required fields are missing: [StageName] --- for SFDC record with ID : null,  

User-added image
User-added image
User-added image
User-added image
User-added image
Hello

Does anyone know how I could update a Contact Status field to the custom value of "Opportunity" when a new Opportunity is created then update the Status again when the Opportunity is closed?  Note, the Org is Professional Edition so I can't use Workflow Rules for this and I have no experience/knowledge of Triggers.

Any help would be appreciated!
Hello

I'm hoping someone can help me write a Test Class for this Trigger please?  I have attempted it (first time!) but am having issues with the "insert" line/element (note, the ID's are false ID's for this example):

Test Class:

@isTest 
public class ChildAccountOwnerUpdate {
        static testMethod void ParentChildOwner()   {
        
        Account a = new Account();
        a.Name ='Test Account' ;
        a.ParentId = '0018E00000glxyz';
        a.OwnerId = '005D0000007dxyz';    
        insert ;
       
            }

}

Trigger:

Trigger ParentChildOwner on Account (Before Insert, Before Update, After UnDelete) {
02     
03    List<Account> comingAccounts      = New List<Account>();
04    List<Id> comingAccountsParentIds  = New List<Id>();
05     
06    If(Trigger.IsInsert || Trigger.IsUpdate || Trigger.IsUnDelete){
07        For(Account act : Trigger.New)
08        {
09            If(act.ParentId != NULL)
10            {
11               comingAccounts.add(act);
12               comingAccountsParentIds.add(act.ParentId);
13            }
14             
15        }
16    }
17     
18    List<Account> fetchingParentAccount = [Select Id, OwnerID FROM Account WHERE Id=:comingAccountsParentIds AND OwnerID != NULL];
19    //system.debug('The size of fetchingParentAccount is: ' + fetchingParentAccount.size());
20     
21    For(Account EveryAct : comingAccounts)
22    {
23        //system.debug('EveryAct existing owner id is: ' + EveryAct.OwnerId);
24         
25        For(Account EveryParent : fetchingParentAccount)
26        {
27            If(EveryAct.ParentId == EveryParent.Id)
28            {
29                EveryAct.OwnerId = EveryParent.OwnerId;
30            }
31        }
32         
33        //system.debug('EveryAct new owner id is: ' + EveryAct.OwnerId);
34    }
35}
I have never created a Trigger before but I believe when I'm trying to achieve is (relatively!) simple?!  I would like new Child Account Record Owners to have the same owner as the Parent Account Record Owner when the Child is created.  Is this possible?
Hello

I have successfully installed the Know Your Enemy App from AppExchange by Salesforce Labs however, the News and Twitter Feeds don't work.  These are Visualforce pages.  Does anyone know how I can fix this?  

Many thanks in advance.
Hello

I'm hoping someone can help me as I have very little developer experience!

I'm receiving the Too many SOQL queries: 101 error.  The code is below.  Can someone please advise how I can fix this?  Any help would be greatly appreciated!  I've removed most of the commented out statements.

trigger OpportunityLineItemTrigger on OpportunityLineItem (after delete, before insert, after insert, before update,after update) {
    
    if(Trigger.isAfter){
        if(Trigger.isDelete){
            // Flag opps having OLIs with different end dates
            OpportunityLineItemTriggerMethods.checkLineItemEndDates(trigger.old);

            //delete related RevenueScheduleItems
            OpportunityLineItemTriggerMethods.removeRevenueScheduleItems(trigger.old);
            
            // Create Deleted_OpportunityLineItem objects, for the Cast Iron integration.
            OpportunityLineItemTriggerMethods.createDeletedLineItemObjects(trigger.old);
            

        }else if(Trigger.isUpdate){
            //copy the modified fields from OLI to related RSI records
            OpportunityLineItemTriggerMethods.updateRevenueScheduleItems(trigger.newMap,trigger.oldMap);
            
            // Add any new revenue schedule items, if the term is increased and it's a closed consulting opportunity line item.
            OpportunityLineItemTriggerMethods.createAdditionalRevenueScheduleItems(trigger.new, trigger.oldMap);
        }
    }   
    
    if(Trigger.isBefore && (Trigger.isInsert || Trigger.isUpdate)){
        
        
        OpportunityLineItemTriggerMethods.opportunityLineItemExchangeRateStamping(Trigger.new, Trigger.oldMap);
          
        OpportunityLineItemTriggerMethods.calculatePPLTotalPrice(Trigger.isInsert, Trigger.new, Trigger.oldMap);
        for(OpportunityLineItem oli:Trigger.New)
        {
          
            Double upLift = oli.Uplift_Percentage__c == null ? 0.0 : oli.Uplift_Percentage__c;
            Double term = oli.term__c == null ? 0.0 : oli.term__c;
            
            Double multiplier = (1.0 + (upLift/100)) * term * 
                    (oli.Company_type_factor__c == null || oli.Company_type_factor__c == 0.0 ? 1.0 : oli.Company_type_factor__c) *
                    (oli.Company_size_factor__c == null || oli.Company_size_factor__c == 0.0 ? 1.0 : oli.Company_size_factor__c);
            Double ppm = oli.Previous_Price_Per_Month__c == null ? 0.0 : oli.Previous_Price_Per_Month__c;
            Double listPrice = oli.ListPrice == null ? 0.0 : oli.ListPrice;
            Double researchAmount = oli.Research_Amount_Price__c == null ? 0.0 : oli.Research_Amount_Price__c;
            Double scheduledDiscount = oli.Scheduled_Discount__c == null ? 0.0 : oli.Scheduled_Discount__c;
            Double unitPrice = oli.UnitPrice == null ? 0.0 : oli.UnitPrice;
            
            oli.Research_Amount_Price__c = (ppm == 0.0) ? (listPrice / 12) * multiplier :ppm * multiplier;
            Double researchAmount1 = oli.Research_Amount_Price__c;
            oli.Discount_Gap__c = (listPrice == 0) ? 0 : researchAmount1 * (1-(scheduledDiscount/100)) - unitPrice; 
        }
    }
    
      if(Trigger.isBefore && Trigger.isInsert){ 
        OpportunityLineItemTriggerMethods.defaultStartDate(Trigger.new);
    }
    
    // 15/06/2012 DP Update
    if (Trigger.isAfter && Trigger.isInsert) {
        OpportunityLineItemTriggerMethods.createRevenueScheduleItems(Trigger.new);
    }
    
    if(Trigger.isAfter ){
        // automatically apply scheduled discounts 
        // future methods can't take sObject arguments .
        OpportunityLineItemTriggerMethods.checkScheduledDiscounts(trigger.new,trigger.oldMap);
        
        // Flag opps having OLIs with different end dates
        if (!Trigger.isDelete){
            OpportunityLineItemTriggerMethods.checkLineItemEndDates(trigger.new);       
        }
    }
    
}
Hi, sorry to re-start this conversation, but I'm having similar problems to Andrew Eversley with regards to creating the visual workflow in the Trailhead Challenge. Can anyone advise where I'm going wrong please?

The error message is: 
caused by element : FlowRecordCreate.Opportunity_Create
caused by: UPSERT --- UPSERT FAILED --- ERRORS : (REQUIRED_FIELD_MISSING) Required fields are missing: [StageName] --- for SFDC record with ID : null,  

User-added image
User-added image
User-added image
User-added image
User-added image
Having a challenging day with all of my Trailhead exercises today, All 3 have not gone well, I guess this is a learning experience

Ok, here is the error I'm receiving for his challenge. 
Challenge not yet complete... here's what's wrong: 
A Visualforce page named 'FlowPage' was not found.

I will add the screenshots below:
1. New Customer Flow
New Customer Flow
2. FlowScreen
2. FlowScreen

3. Account Creation
Account Creation
3. Contact Creation

4. Contact Creation
Opportunity Creation

4. Opportunity


I will add the screenshots for the Visual Force Pages on part II of this
I'm new to the developer side of Salesforce and was hoping someone could give me guidance on creating a Workflow rule to alert the Ideas creator when a new Comment has been added?  Many thanks in advance.