• Jeff Gillis
  • NEWBIE
  • 0 Points
  • Member since 2019

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

I am trying to setup a web service where I call to get a list of opportunity records based on converted leads from a specific source.  I am trying to create a list of opportunity ids based on a SOQL query against the lead object, but am getting the "Illegal assignment from List to List" error and had try to google that without any luck.

My simple httpget is below:
@RestResource(urlMapping='/getOpportunityInfo/*')
global with sharing class ZoomInfoAPI {

    
    @HttpGet
    global static List<Opportunity> doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        List<String> convertOppList = new List<String>();
		convertOppList = [SELECT ConvertedOpportunityId FROM Lead WHERE LeadSource = 'ZoomInfo' AND Status = 'Converted']; 
        List <Opportunity> oppList = [SELECT Id, Name, Amount, Owner_Name__c, Contact_Name__c, AccountId, Account_Name__c, Account.Name, Account.ShippingStreet, Account.ShippingCity, Account.ShippingState, Account.ShippingPostalCode, Account.ShippingCountry, Stagename, IPG_Market_Code__c, IPG_App_Code__c, CloseDate, Opp_Shipping_Address__c, IPG_Industry_Type__c, Createddate FROM Opportunity WHERE Id IN :convertOppList];
        System.debug(oppList);
        return oppList;
        
    }
    
}
I am new to apex and am likely making some fundamental mistake.  Any quick advise would be greatly appreciated!

Thank you!
Hi,

I am in the process of implementing the territories within Salesforce and was following the instructions and sample code from the help documents here: 
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_TerritoryMgmt_OpportunityTerritory2AssignmentFilter.htm

I have setup the apex class which is as follows:
/*** Apex version of the default logic.
* If opportunity's assigned account is assigned to
*  Case 1: 0 territories in active model
*            then set territory2Id = null
*  Case 2: 1 territory in active model
*            then set territory2Id = account's territory2Id
*  Case 3: 2 or more territories in active model
*            then set territory2Id = account's territory2Id that is of highest priority.
*            But if multiple territories have same highest priority, then set territory2Id = null 
*/
global class OppTerrAssignDefaultLogicFilter implements TerritoryMgmt.OpportunityTerritory2AssignmentFilter { 
    /**
     * No-arg constructor.
     */ 
     global OppTerrAssignDefaultLogicFilter() {}

     /**
      * Get mapping of opportunity to territory2Id. The incoming list of opportunityIds contains only those with IsExcludedFromTerritory2Filter=false.
      * If territory2Id = null in result map, clear the opportunity.territory2Id if set.
      * If opportunity is not present in result map, its territory2Id remains intact.
      */
    global Map<Id,Id> getOpportunityTerritory2Assignments(List<Id> opportunityIds) { 
        Map<Id, Id> OppIdTerritoryIdResult = new Map<Id, Id>();

        // Get the active territory model Id
        Id activeModelId = getActiveModelId();

        if(activeModelId != null){
            List<Opportunity> opportunities =
              [Select Id, AccountId, Territory2Id from Opportunity where Id IN :opportunityIds];
            Set<Id> accountIds = new Set<Id>();
            // Create set of parent accountIds
            for(Opportunity opp:opportunities){
                if(opp.AccountId != null){
                    accountIds.add(opp.AccountId);
                    }
                }

                Map<Id,Territory2Priority> accountMaxPriorityTerritory = getAccountMaxPriorityTerritory(activeModelId, accountIds);

            // For each opportunity, assign the highest priority territory if there is no conflict, else assign null.
            for(Opportunity opp: opportunities){
               Territory2Priority tp = accountMaxPriorityTerritory.get(opp.AccountId);
               // Assign highest priority territory if there is only 1.
              if((tp != null) && (tp.moreTerritoriesAtPriority == false) && (tp.territory2Id != opp.Territory2Id)){
                   OppIdTerritoryIdResult.put(opp.Id, tp.territory2Id);
               }else{
                   OppIdTerritoryIdResult.put(opp.Id, null);
               }
            }
        }
        return OppIdTerritoryIdResult;
    }
    
    /**
      * Query assigned territoryIds in active model for given accountIds.
      * Create a map of accountId to max priority territory.
      */
     private Map<Id,Territory2Priority> getAccountMaxPriorityTerritory(Id activeModelId, Set<Id> accountIds){
        Map<Id,Territory2Priority> accountMaxPriorityTerritory = new Map<Id,Territory2Priority>();
        for(ObjectTerritory2Association ota:[Select ObjectId, Territory2Id, Territory2.Territory2Type.Priority from ObjectTerritory2Association where objectId IN :accountIds and Territory2.Territory2ModelId = :activeModelId]){
            Territory2Priority tp = accountMaxPriorityTerritory.get(ota.ObjectId);

            if((tp == null) || (ota.Territory2.Territory2Type.Priority > tp.priority)){
                // If this is the first territory examined for account or it has greater priority than current highest priority territory, then set this as new highest priority territory.
                tp = new Territory2Priority(ota.Territory2Id,ota.Territory2.Territory2Type.priority,false);
            }else if(ota.Territory2.Territory2Type.priority == tp.priority){
                // The priority of current highest territory is same as this, so set moreTerritoriesAtPriority to indicate multiple highest priority territories seen so far.
                tp.moreTerritoriesAtPriority = true;
            }
            
            accountMaxPriorityTerritory.put(ota.ObjectId, tp);
        }
        return accountMaxPriorityTerritory;
    }


    /**
     * Get the Id of the Active Territory Model.
     * If none exists, return null.
     */
    private Id getActiveModelId() {
        List<Territory2Model> models = [Select Id from Territory2Model where State = 'Active'];
        Id activeModelId = null;
        if(models.size() == 1){
            activeModelId = models.get(0).Id;
        }

        return activeModelId;
    }

    /**
    * Helper class to help capture territory2Id, its priority, and whether there are more territories with same priority assigned to the account.
    */
    @testVisible
    private class Territory2Priority {
        public Id territory2Id { get; set; }
        public Integer priority { get; set; }
        public Boolean moreTerritoriesAtPriority { get; set; }

        @testVisible
        Territory2Priority(Id territory2Id, Integer priority, Boolean moreTerritoriesAtPriority){
            this.territory2Id = territory2Id;
            this.priority = priority;
            this.moreTerritoriesAtPriority = moreTerritoriesAtPriority;
        }
    }
}

I had found a test class here for this:
@isTest
private class OppTerrAssignDefaultLogicFilterTest {
    
    @isTest
    private static void testActiveModel() {
        // This method is just for code coverage. You can't activate a territory model from code.
        OppTerrAssignDefaultLogicFilter filter = new OppTerrAssignDefaultLogicFilter();
        Id modelId = filter.ActiveModelId;
    }
    
    @isTest
    private static void testOppTerritory() {
        Territory2 terr = new Territory2();
        Territory2 terr2 = new Territory2();
        OppTerrAssignDefaultLogicFilter filter = new OppTerrAssignDefaultLogicFilter();
        
        System.runAs(new User(Id = UserInfo.getUserId())) {
            Territory2Model tm = new Territory2Model(Name = 'test', DeveloperName ='test');
            insert tm;
            
            filter.ActiveModelId = tm.Id; //set the active model Id since it can't be queried
            
            Territory2Type tt = [Select Id from Territory2Type limit 1];
            
            terr = new Territory2(Name = 'Test Territory', DeveloperName = 'TestTerritory', Territory2ModelId = tm.Id, Territory2TypeId = tt.Id);
            insert terr;
            
            terr2 = new Territory2(Name = 'Test Territory2', DeveloperName = 'TestTerritory2', Territory2ModelId = tm.Id, Territory2TypeId = tt.Id);
            insert terr2;
        }
        
        Account a = new Account(Name = 'Test Account');
        insert a;
        
		Contact testContact = new Contact(
                FirstName = 'First',
                LastName = 'Last',
                Email = 'test@test.com',
                AccountId = a.Id
        );
        insert testContact;        
        
        ObjectTerritory2Association ota = new ObjectTerritory2Association(AssociationCause  = 'Territory2Manual', ObjectId = a.Id, Territory2Id = terr.Id);
        insert ota;
        
        Opportunity opp = new Opportunity(
                Name = 'Test Opp',
                AccountId = a.Id,
                //RecordTypeId = String.isNotBlank(oppRecTypeId) ? oppRecTypeId : null,
                StageName = 'Prospecting',
                OpportunityContact__c = testContact.Id,
                Type = 'Systems',
                CloseDate = System.today(),
                Market_Segment__c = 'General Industry',
                End_User_Type__c = 'Agricultural'
        );
        insert opp;   
        
                
        Map<Id, Id> resultMap = filter.getOpportunityTerritory2Assignments(new List<Id>{opp.Id});
        
        System.assertEquals(terr.Id, resultMap.get(opp.Id));
        
        ObjectTerritory2Association ota2 = new ObjectTerritory2Association(AssociationCause  = 'Territory2Manual', ObjectId = a.Id, Territory2Id = terr2.Id);
        insert ota2;
        
        resultMap = filter.getOpportunityTerritory2Assignments(new List<Id>{opp.Id});
        
        System.assertEquals(null, resultMap.get(opp.Id), 'No territory should be assinged as 2 have the same priority');
    }
    
}

I am getting an error at lines 8 and 20 on the test class that states:
Variable does not exist: ActiveModelId

Can anyone advise as to how to resolve?

Many Thanks!
 
Hi,

I have a user that encounters an error when clicking into a Lead record.  When they click the Lead record from a list view, they recieve an error message that states: "Problem occured while initializing component."

I logged in as the user and was able to reproduce the same error.  I ran the debug logs while repeating the steps, but did not see an error when reviewing the logs.

The screenshot of the error is here:
User-added image
Any advice on how to troubleshoot would be greatly appreciated!
 
Thanks!
Hi,

I have a process builder workflow setup that sends out new task email notifications.  I would like to differentiate the the email notifications based on the queue that it is getting sent to.  

A simplified example is that we have one queue that is for the US Sales and another queue that is for International Sales.  I would like one style email template to be sent for the US and another for international.  I don't want to go off of the queue name since I would need to maintain that and this list will grow over time.

I originally was looking into custom metadata types, but not sure if that will work.  Any advise is greatly appreciated!  Thanks!
Hi,

I have enabled Campaign Influences and the default/active attribution model is the out-of-the-box Even Touch model.  The timeframe for association is currently blank.

My question is around the expected functionality for attributing campaign influence on existing opportunities.  The situation is that there is a lead that is a campaign member on the campaign.  That lead has been converted to an existing account, existing contact, and existing open opportunity.  Since the opportunity is still open, I would expect that since the lead has been linked to it, it would have the campaign that the lead is a member on have some attribution to the opportunity, right?

What is am seeing is that if the lead is converted to an existing account, existing contact, and existing open opportunity, then there is no campaign influence attributed to the opportunity.  This is not what I would expect, but want to confirm.

For the other scenario of converting the lead to an existing account, existing cotact, and creating a new opportunity, then the opportunity is given campaign influence attribution.  This is expected outcome.

Can you help confirm what the expected functionality should be and why this is working this way?

Thanks,
Jeff
Hi,

I have enabled Campaign Influences and the default/active attribution model is the out-of-the-box Even Touch model.  The timeframe for association is currently blank.

My question is around the expected functionality for attributing campaign influence on existing opportunities.  The situation is that there is a lead that is a campaign member on the campaign.  That lead has been converted to an existing account, existing contact, and existing open opportunity.  Since the opportunity is still open, I would expect that since the lead has been linked to it, it would have the campaign that the lead is a member on have some attribution to the opportunity, right?

What is am seeing is that if the lead is converted to an existing account, existing contact, and existing open opportunity, then there is no campaign influence attributed to the opportunity.  This is not what I would expect, but want to confirm.

For the other scenario of converting the lead to an existing account, existing cotact, and creating a new opportunity, then the opportunity is given campaign influence attribution.  This is expected outcome.

Can you help confirm what the expected functionality should be and why?

Thanks,
Jeff
I am looking to associate ContentDocuments to Product2 records based on values in the ContentVersion record. For example I am uploading a new File record in Salesforce that is a document about Product A. When the record is created it will create a ContentDocument and ContentVersion. In the ContentVersion there are two custom fields called "Product Family" and "Product Type". On Product2 there are also two custom fields called "Product Family" and "Product Type".
I would like to create a ContentDocumentLink record that links the document to the product if the fields match up.
The apex trigger that I am writing right now is as follows (I'm new to Apex!)
 
trigger documentLinking on ContentVersion (after insert, after update) {

//Build a list of ContentVersion Ids that do not have a blank Product Family or Product Type for records in trigger.new
List<Id> listOfContentVersionId = new List<Id>();
List<String> listOfProductFamily = new LIst<String>();
List<String> listOfProductType = new List<String>();
for(ContentVersion cv : Trigger.new) {
    if(cv.Product_Family__c != null && cv.Product_Type__c != null)
    {
        listOfContentVersionId.add(cv.Id);
        listOfProductFamily.add(cv.Product_Family__c);
        listOfProductType.add(cv.Product_Type__c);

        System.debug('List size' + strings.size());
    }
}

if(listOfContentVersionId.size()>0)
{
    //Query for Product records that have the same Product Family and Product Type as the document that is being added/updated
    List<String> matchingProducts =    [SELECT Id
                                        FROM Product2
                                        WHERE Product_Family__c = :cv.Product_Family__c
                                        AND Product_Type__c = :cv.Product_Type__c];

                                        System.debug('List size' + strings.size());
}

//Pull in the matching Product records to then create a ContentDocumentLink record to them
for(Product p : matchingProducts){
    ContentDocumentLink cdl = new ContentDocumentLink   (ContentDocumentId = cv.ContentDocumentId,
                                                        LinkedEntityId = matchingProducts.Id,
                                                        ShareType = 'V');


insert p; 
}

}