• wcraig
  • NEWBIE
  • 30 Points
  • Member since 2016
  • Senior Salesforce Admin
  • Covetrus


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 13
    Replies

https://developer.salesforce.com/docs/component-library/documentation/lwc/use_config_for_app_builder_email_app_pane

The component built here doesn't work - there is something wrong with the way it references the to and from data ~ and I can't find any documentation as to how to work with those variables properly.

  • January 30, 2020
  • Like
  • 0

I have a simple trigger on opportunity that populates a primary contact on the opportunity from opportunity contact roles.

The test class is getting 19/20 coverage - with the last missing line being a Map.put used to populate a map used to save opportunity id, contact id. The test class tests that this is working properly - I'm not sure what I may be missing to get coverage.

 

The Trigger:

// Built by Will Craig 4.25.2019
//
// Trigger for initiating all classes for Opportunity.

trigger Opportunity on Opportunity (before insert, before update, after insert, after update) {

    // Routing for before triggers.
    if(Trigger.isBefore){
        
        if(Trigger.isUpdate){

            opportunityPrimaryContact.PrimaryContactProcessor(Trigger.new, Trigger.oldMap);

        }else if(Trigger.isInsert){

            opportunityPrimaryContact.PrimaryContactProcessor(Trigger.new);

        }

    } else if(Trigger.isAfter){

        // After trigger responses

    }

}

The Class:

public class opportunityPrimaryContact {
    
    // Method for handling inserts
    public static void PrimaryContactProcessor(List<Opportunity> Opportunities) {

        // Create a map for use when updating Primary_Contact__c on Opportunties
        Map<Id,Id> pocrMap = new Map<Id,Id>();
        
        // Create a set of OpportunityIds for use in the OCR query.
        Set<Id> oppidSet = new Set<Id>();
        for(Opportunity opp : Opportunities){
            oppidSet.add(opp.id);
        }

        // Retrieve primary OCRs and populate a map for retrieving them by OpportunityId
        List<OpportunityContactRole> ocrs = [SELECT ContactId,OpportunityId FROM OpportunityContactRole WHERE OpportunityId IN: oppidSet AND IsPrimary = true];
        for(OpportunityContactRole ocr : ocrs){
            pocrMap.put(ocr.OpportunityId,ocr.ContactId);
        }

        // Iterate through opportunities and set Primary_Contact__c, leveraging pocrMap.
        for(Opportunity opp : Opportunities){
            opp.Primary_Contact__c = pocrMap.get(opp.Id);
        }

        // Updates not required in before triggers.

    }

    // Method for handling updates (via overload)
    public static void PrimaryContactProcessor(List<Opportunity> Opportunities, Map<ID,sObject> TriggerOldMap) {

        // Create a map for use when updating Primary_Contact__c on Opportunties
        Map<Id,Id> pocrMap = new Map<Id,Id>();
        
        // Create a set of OpportunityIds for use in the OCR query.
        Set<Id> oppidSet = new Set<Id>();
        for(Opportunity opp : Opportunities){
            oppidSet.add(opp.id);
        }

        // Retrieve primary OCRs and populate a map for retrieving them by OpportunityId
        List<OpportunityContactRole> ocrs = [SELECT ContactId,OpportunityId FROM OpportunityContactRole WHERE OpportunityId IN: oppidSet AND IsPrimary = true];
        for(OpportunityContactRole ocr : ocrs){
   // line below is what is not covered.         pocrMap.put(ocr.OpportunityId,ocr.ContactId);
        }


        // Iterate through opportunities and set Primary_Contact__c, leveraging pocrMap.
        for(Opportunity opp : Opportunities){
            opp.Primary_Contact__c = pocrMap.get(opp.Id);
        }

        // Updates not required in before triggers.

    }

}
 

Test Class:

@IsTest
public class opportunityPrimaryContact_TEST {
    
    @IsTest
    private static void create_TEST() {

        Test.StartTest();

        User u = new User();
        u.ProfileId = [SELECT Id FROM Profile WHERE Name = 'Standard User'].Id;
        u.LastName = 'last';
        u.Email = 'test@test.com ';
        u.Username = 'test@test.com.' + System.currentTimeMillis();
        u.CompanyName = 'TEST';
        u.Title = 'title';
        u.Alias = 'alias';
        u.TimeZoneSidKey = 'America/Los_Angeles';
        u.EmailEncodingKey = 'UTF-8';
        u.LanguageLocaleKey = 'en_US';
        u.LocaleSidKey = 'en_US';

        Insert u;

        Account acc = new Account();
        acc.Name = 'Test Account';
        acc.ownerid = u.id;

        Opportunity opp = new Opportunity();
        opp.Name = 'Test Opportunity';
        opp.StageName = 'Target';
        opp.CloseDate = Date.Today();
        opp.ownerid = u.id;

        Insert opp;

        Contact c1 = new Contact();
        c1.Firstname = 'Test1First';
        c1.Lastname = 'Test1Last';
        c1.AccountId = acc.id;

        Insert c1;

        OpportunityContactRole ocr1 = new OpportunityContactRole();
        ocr1.ContactId = c1.id;
        ocr1.OpportunityId = opp.id;
        ocr1.IsPrimary = true;
        ocr1.Role = 'Decision Maker';

        Insert ocr1;

        Contact c2 = new Contact();
        c2.Firstname = 'Test2First';
        c2.Lastname = 'Test2Last';
        c2.AccountId = acc.id;

        Insert c2;

        OpportunityContactRole ocr2 = new OpportunityContactRole();
        ocr2.ContactId = c2.id;
        ocr2.OpportunityId = opp.id;
        ocr2.IsPrimary = false;
        ocr2.Role = 'Decision Maker';
        
        Insert ocr2;

        Update opp;
        
        Test.StopTest();

        OpportunityContactRole ocr = [SELECT Id,
                                        ContactId,Contact.Name,OpportunityId 
                                        FROM OpportunityContactRole 
                                        WHERE OpportunityId =: opp.id 
                                        AND IsPrimary = true
                                        ];

        

        Opportunity oppupdated = [SELECT Id,Primary_Contact__c from Opportunity WHERE ID =: opp.id];

        System.debug(ocr);
        System.debug(opp.Primary_Contact__c);
        System.assertEquals(ocr.ContactId,oppupdated.Primary_Contact__c);
        
    }

}
  • April 26, 2019
  • Like
  • 0
I'm struggling to understand how to pull triggers and a apex classes FROM a sandbox using visual studio code / salesforce dx. I'd like to pull triggers down from an org to edit them in a batch but can't find the method to do that. I've looked around at documentation but I've struggled to find anything that would allow me to do this specifically.
  • December 29, 2017
  • Like
  • 0

There was an unhandled exception. Please reference ID: KLNTXAZY. Error: Faraday::ClientError. Message: MALFORMED_QUERY: When retrieving results with Metadata or FullName fields, the query qualificatio​ns must specify no more than one row for retrieval. Result size: 2

I have a flow that allows you to choose the product type, then the product, which creates the product, then asks if you want to add more products and goes back to the start. Seems to work perfectly. Not sure what this error is.

I have a simple trigger on opportunity that populates a primary contact on the opportunity from opportunity contact roles.

The test class is getting 19/20 coverage - with the last missing line being a Map.put used to populate a map used to save opportunity id, contact id. The test class tests that this is working properly - I'm not sure what I may be missing to get coverage.

 

The Trigger:

// Built by Will Craig 4.25.2019
//
// Trigger for initiating all classes for Opportunity.

trigger Opportunity on Opportunity (before insert, before update, after insert, after update) {

    // Routing for before triggers.
    if(Trigger.isBefore){
        
        if(Trigger.isUpdate){

            opportunityPrimaryContact.PrimaryContactProcessor(Trigger.new, Trigger.oldMap);

        }else if(Trigger.isInsert){

            opportunityPrimaryContact.PrimaryContactProcessor(Trigger.new);

        }

    } else if(Trigger.isAfter){

        // After trigger responses

    }

}

The Class:

public class opportunityPrimaryContact {
    
    // Method for handling inserts
    public static void PrimaryContactProcessor(List<Opportunity> Opportunities) {

        // Create a map for use when updating Primary_Contact__c on Opportunties
        Map<Id,Id> pocrMap = new Map<Id,Id>();
        
        // Create a set of OpportunityIds for use in the OCR query.
        Set<Id> oppidSet = new Set<Id>();
        for(Opportunity opp : Opportunities){
            oppidSet.add(opp.id);
        }

        // Retrieve primary OCRs and populate a map for retrieving them by OpportunityId
        List<OpportunityContactRole> ocrs = [SELECT ContactId,OpportunityId FROM OpportunityContactRole WHERE OpportunityId IN: oppidSet AND IsPrimary = true];
        for(OpportunityContactRole ocr : ocrs){
            pocrMap.put(ocr.OpportunityId,ocr.ContactId);
        }

        // Iterate through opportunities and set Primary_Contact__c, leveraging pocrMap.
        for(Opportunity opp : Opportunities){
            opp.Primary_Contact__c = pocrMap.get(opp.Id);
        }

        // Updates not required in before triggers.

    }

    // Method for handling updates (via overload)
    public static void PrimaryContactProcessor(List<Opportunity> Opportunities, Map<ID,sObject> TriggerOldMap) {

        // Create a map for use when updating Primary_Contact__c on Opportunties
        Map<Id,Id> pocrMap = new Map<Id,Id>();
        
        // Create a set of OpportunityIds for use in the OCR query.
        Set<Id> oppidSet = new Set<Id>();
        for(Opportunity opp : Opportunities){
            oppidSet.add(opp.id);
        }

        // Retrieve primary OCRs and populate a map for retrieving them by OpportunityId
        List<OpportunityContactRole> ocrs = [SELECT ContactId,OpportunityId FROM OpportunityContactRole WHERE OpportunityId IN: oppidSet AND IsPrimary = true];
        for(OpportunityContactRole ocr : ocrs){
   // line below is what is not covered.         pocrMap.put(ocr.OpportunityId,ocr.ContactId);
        }


        // Iterate through opportunities and set Primary_Contact__c, leveraging pocrMap.
        for(Opportunity opp : Opportunities){
            opp.Primary_Contact__c = pocrMap.get(opp.Id);
        }

        // Updates not required in before triggers.

    }

}
 

Test Class:

@IsTest
public class opportunityPrimaryContact_TEST {
    
    @IsTest
    private static void create_TEST() {

        Test.StartTest();

        User u = new User();
        u.ProfileId = [SELECT Id FROM Profile WHERE Name = 'Standard User'].Id;
        u.LastName = 'last';
        u.Email = 'test@test.com ';
        u.Username = 'test@test.com.' + System.currentTimeMillis();
        u.CompanyName = 'TEST';
        u.Title = 'title';
        u.Alias = 'alias';
        u.TimeZoneSidKey = 'America/Los_Angeles';
        u.EmailEncodingKey = 'UTF-8';
        u.LanguageLocaleKey = 'en_US';
        u.LocaleSidKey = 'en_US';

        Insert u;

        Account acc = new Account();
        acc.Name = 'Test Account';
        acc.ownerid = u.id;

        Opportunity opp = new Opportunity();
        opp.Name = 'Test Opportunity';
        opp.StageName = 'Target';
        opp.CloseDate = Date.Today();
        opp.ownerid = u.id;

        Insert opp;

        Contact c1 = new Contact();
        c1.Firstname = 'Test1First';
        c1.Lastname = 'Test1Last';
        c1.AccountId = acc.id;

        Insert c1;

        OpportunityContactRole ocr1 = new OpportunityContactRole();
        ocr1.ContactId = c1.id;
        ocr1.OpportunityId = opp.id;
        ocr1.IsPrimary = true;
        ocr1.Role = 'Decision Maker';

        Insert ocr1;

        Contact c2 = new Contact();
        c2.Firstname = 'Test2First';
        c2.Lastname = 'Test2Last';
        c2.AccountId = acc.id;

        Insert c2;

        OpportunityContactRole ocr2 = new OpportunityContactRole();
        ocr2.ContactId = c2.id;
        ocr2.OpportunityId = opp.id;
        ocr2.IsPrimary = false;
        ocr2.Role = 'Decision Maker';
        
        Insert ocr2;

        Update opp;
        
        Test.StopTest();

        OpportunityContactRole ocr = [SELECT Id,
                                        ContactId,Contact.Name,OpportunityId 
                                        FROM OpportunityContactRole 
                                        WHERE OpportunityId =: opp.id 
                                        AND IsPrimary = true
                                        ];

        

        Opportunity oppupdated = [SELECT Id,Primary_Contact__c from Opportunity WHERE ID =: opp.id];

        System.debug(ocr);
        System.debug(opp.Primary_Contact__c);
        System.assertEquals(ocr.ContactId,oppupdated.Primary_Contact__c);
        
    }

}
  • April 26, 2019
  • Like
  • 0
I can't pass this challenge Process Design Without Limits Learn About Object Design-Time Limits. I have below error message. Can anypne please help.

Challenge Not yet complete... here's what's wrong: 
Changing the owner of the Account record failed to update the 'Account_Owner_Name_Process__c' field for the Case object . Make sure that the process is correct and that it is activated.https://trailhead.salesforce.com/modules/process-design-without-limits/units/process-design-without-limits-object

There was an unhandled exception. Please reference ID: KLNTXAZY. Error: Faraday::ClientError. Message: MALFORMED_QUERY: When retrieving results with Metadata or FullName fields, the query qualificatio​ns must specify no more than one row for retrieval. Result size: 2

I have a flow that allows you to choose the product type, then the product, which creates the product, then asks if you want to add more products and goes back to the start. Seems to work perfectly. Not sure what this error is.

The call for service field description in the requirement is way different than what trailhead is actually validating.

User-added image
I'm unable to check step 2: Automate Accounts because I'm receiving this error: Challenge Not yet complete... here's what's wrong: 
There was an unexpected error while verifying this challenge. Usually this is due to some pre-existing configuration or code in the challenge Org. We recommend using a new Developer Edition (DE) to check this challenge. If you're using a new DE and seeing this error, please post to the developer forums and reference error id: ZKCVFIZH