• AL
  • NEWBIE
  • 110 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 26
    Questions
  • 53
    Replies
Hello, I have a SOAP callout to an external webservice and I'd like to retrieve the records from the external service and insert them into Salesforce. If I query on a specific record from the external system, I can insert that record into Salesforce. However when I query on multiple records, they're not being inserted into SF. I tried creating a while loop and adding the records to a list and then insert the list, but that hasn't worked. Any help would be appreciated. Thank you.
 
public class ListOutboundFax {
    
      public static void getListOutBoundRecords(Integer customerId ){     
        Concord__c con = new Concord__c();
        List<Concord__c> lstConcord = new  List<Concord__c>();
        
        accountmanagementreportingwebservice.AccountManagementReportingWebserviceSoap s= new accountmanagementreportingwebservice.AccountManagementReportingWebserviceSoap();
        accountmanagementreportingwebservice.ListOutboundActivityRequest  req = new accountmanagementreportingwebservice.ListOutboundActivityRequest();
        accountmanagementreportingwebservice.ListOutboundActivityResponse res = new accountmanagementreportingwebservice.ListOutboundActivityResponse();
        accountmanagementreportingwebservice.Authentication a =new accountmanagementreportingwebservice.Authentication();
        accountmanagementreportingwebservice.ArrayOfString filter = new accountmanagementreportingwebservice.ArrayOfString();
        accountmanagementreportingwebservice.Filter filters = new accountmanagementreportingwebservice.Filter();
        
                   
        a.Username = '-------';
        a.Password = '-------'; 
        req.Authentication = a;
        req.CustomerId = customerId;
        req.EndDate = date.valueOf('2019-11-12T06:03:15-08:00');
        req.ExcludeSubLevelEntries = Boolean.valueOf('true');
        req.PageIndex = 0;
        req.PageSize = 100;
        req.SortOption = 0;
        req.StartDate = date.valueOf('2019-11-11T06:03:15-08:00');
        
        res = s.ListOutboundActivity(req);
        String jsonResponse = (JSON.serializePretty(res));
    
        System.debug(jsonResponse);
   Integer count = 0;     
   JSONParser parser = JSON.createParser(jsonResponse);
          while(parser.nextToken() != null && count < lstConcord.size()){
              if(parser.getCurrentToken() == JSONToken.FIELD_NAME){
               parser.nextValue();
                if(parser.getCurrentName() == 'id') {
                   con.JOB_ID__c = parser.getText(); 
    //               System.debug(con.Name);
                }
                  
                 else if(parser.getCurrentName() == 'dur'){
                            con.Duration__c = Integer.valueOf(parser.getText());
    //                        System.debug(con.Duration__c);

                        }
                        
                        else if(parser.getCurrentName() == 'pgct'){
                            con.Delivered_Pages__c = Integer.valueOf(parser.getText());
    //                        System.debug(con.Delivered_Pages__c);
                        }
                        
                        else if(parser.getCurrentName() == 'dt'){
                            con.Stop_Date__c = Date.valueOf(parser.getText());
  //                          System.debug(con.Stop_Date__c);
                        }
                        
                        else if(parser.getCurrentName() == 'FaxNumber'){
                            con.Fax__c = parser.getText();
 //                           System.debug(con.Fax__c);
                        }  
                  
                   else if(parser.getCurrentName() == 'fcc'){
                            con.Sender_Country__c = parser.getText();
   //                         System.debug(con.Sender_Country__c);
                        } 
                  
                  else if(parser.getCurrentName() == 'cid'){
                            con.Concord_Account_ID__c = parser.getText();
    //                        System.debug(con.Concord_Account_ID__c);
                        } 
                  

                  lstConcord.add(con);
                  System.debug('Size of List' + lstConcord.size());
              }  
              
              System.debug('Size of List' + lstConcord.size());
              count++;
              
              
          }
  
                        if(lstConcord.size() > 0 ){
            try{
                
                insert lstConcord;
            }
            
            catch(Exception ex){
                System.debug(ex);
            }
        }
          
          
          
              }
          }

 
  • November 13, 2019
  • Like
  • 0
Hello, I'm looking to create a component that fires an action (i.e. popup modal) if a custom account check box is populated. I have the  popup box appearing if I click on the account's 'edit' button which I overrode, but I'd like to create an 'if' condition. Any help would be appreciated. Thank you. 

Component
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,lightning:actionOverride,force:hasRecordId,force:lightningQuickAction" access="global" >
	
    <aura:attribute name="isModalOpen" type="boolean" default="false"/>
    <aura:attribute name="AOff" type="Account" default="{'sobjectType': 'Account'
                                                        'Offsite_Data_Transfer_Prohibited__c': false}"/>
   
 <!--   <lightning:button variant="brand" label="Override" onclick="{!c.handleModal}" /> -->
    
    
    <force:recordData aura:id="forceRecord"
                recordId="{!v.recordId}"
                targetRecord="{!v.forceRecord}"
                targetFields="{!v.AOff}"
                fields="Id,Offsite_Data_Transfer_Prohibited__c"
                mode="EDIT" />
    
    <aura:handler name="init" value="{!this}" action="{!c.handleModal}" ></aura:handler>
    
  
    <div class="slds-m-around_xx-large">
        
        <!--
        <lightning:button variant="brand"
                          label="What is Modal/PopUp Box?"
                          title="What is Modal/PopUp Box?"
                          onclick="{! c.openModel }" />  -->
    
    <!--Use aura:if tag to display/hide popup based on isModalOpen value-->  
        <aura:if isTrue="{!v.isModalOpen}">
    
     <!-- Modal/Popup Box starts here-->
            <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">


 <div class="slds-modal__container">
                    <!-- Modal/Popup Box Header Starts here-->
                    <header class="slds-modal__header">
                        <lightning:buttonIcon iconName="utility:close"
                                              onclick="{! c.closeModel }"
                                              alternativeText="close"
                                              variant="bare-inverse"
                                              class="slds-modal__close"/>



 <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">OffSite Data Transfer Prohibited</h2>
                    </header>


 <!--Modal/Popup Box Body Starts here-->
                    <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                        <p><b>The transfer of data offiste for this account is prohibited. 
                            </b>
                        </p>
                    </div>

<!--Modal/Popup Box Footer Starts here-->
                    <footer class="slds-modal__footer">
                        <lightning:button variant="neutral"
                                          label="Cancel"
                                          title="Cancel"
                                          onclick="{! c.closeModel }"/>
                        <lightning:button variant="brand"
                                          label="OK"
                                          title="OK"
                                          onclick="{!c.submitDetails}"/>
                    </footer>
                </div>
            </section>
            <div class="slds-backdrop slds-backdrop_open"></div>
        </aura:if>
    </div>
    
</aura:component>

Controller 
 
({
    handleModal: function(component, event, helper) {
       
        // Set isModalOpen attribute to true
    
      component.set("v.isModalOpen", true);
    },
    
      closeModel: function(component, event, helper) {
      // Set isModalOpen attribute to false  
      component.set("v.isModalOpen", false);
   },
    
    
   submitDetails: function(component, event, helper) {
      // Set isModalOpen attribute to false
      //Add your code to call apex method or do some processing
      component.set("v.isModalOpen", false);
   }
    
    
    
})

 
  • October 27, 2019
  • Like
  • 0
Hello, I've created a matching field on the opportunity line item and quote line item objects. When updating the opportunity line item field, I would like the corresponding field on the quote line item to be updated, and vice versa.

When I update the quote line item field, the correspodning field is updated successfully, but when I update the opportunity line item field, the quote line item isn't being updated. Is there something wrong with my opportunity line item trigger? Thank 

Opportunity Line Item Trigger
 
trigger OppSyncPartnerRevShare on OpportunityLineItem (before insert, before update) {
    
   Decimal v2PartnerRev;
    //string vOptyId;
    string vPricebookEntryId;
    string vQuoteId;
    List<QuoteLineItem> qli = new List<QuoteLineItem>([select Id from QuoteLineItem where (QuoteId = :vQuoteId and PricebookEntryId = :vPricebookEntryId)]);
 
    for(OpportunityLineItem oppLine : Trigger.new){
    
        v2PartnerRev = oppLine.X2Partner_Rev_Share_Value__c;
        //vOptyId = oppLine.OpportunityId;
        vPricebookEntryId = oppLine.PricebookEntryId;
        vQuoteId = oppLine.Quote_ID__c;
    }
    for(QuoteLineItem quoteLine : qli){
        
        quoteLine.X2Partner_Rev_Share_Value__c = v2PartnerRev;
    //    qli.add(quoteLine);
     //   update(quoteLine);
    }
  //  update qli;
   
    

}


Quote Line Item Trigger 
 
trigger updateQuoteLineItemPartnerRevShare on QuoteLineItem (before insert, before update) {
    
    Decimal v2PartnerRevShare;
    string vOptyId;
    string vPricebookEntryId;
    string vQuote;
 
    for(QuoteLineItem quoteLine : Trigger.new){
         Quote q = new Quote();
        String oppId = q.OpportunityId;
        vOptyId = oppId;
        vPricebookEntryId = quoteLine.PricebookEntryId;
        
        for(OpportunityLineItem oppLine : [select Id, X2Partner_Rev_Share_Value__c from OpportunityLineItem where (OpportunityId = :vOptyId and PricebookEntryId = :vPricebookEntryId)]){
            v2PartnerRevShare = oppLine.X2Partner_Rev_Share_Value__c;
            //oppLine.
        }
        
   //     quoteLine.X2Partner_Rev_Share_Value__c = v2PartnerRevShare;
   
    }

}

 
  • October 03, 2019
  • Like
  • 0
Hello, I have Salesforce to Salesforce setup and I'm trying to share opportunity records and opportunity products with the target org. We want to be able to manually share the opportunity record with by using the standard external sharing button with S2S. However, we would like to automatically send over opportunity products on any opportunities that we are sharing between the two orgs. Below is the code that I have to try to automatically send over the opp producst but it's not inserting or updating in the target org. Any assistance is appreciated. Thank you. 
 
Class 

public class S2SForward {
    
       public S2SForward(){
        List<PartnerNetworkRecordConnection> oppProds = new  List<PartnerNetworkRecordConnection>();
    }
    
    public static void upsertOLI(List<SObject> oliList){
    
    List <PartnerNetworkRecordConnection> prncList = new List <PartnerNetworkRecordConnection>();
	List <PartnerNetworkConnection> connectionList = new List <PartnerNetworkConnection>([Select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted' AND Id = '04P3i000000004OEAQ']);
	Map <ID, PartnerNetworkConnection> connMap = new Map<ID, PartnerNetworkConnection>([Select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted' AND Id = '04P1Q000000CaoyUAC']);
	Map <ID, ID> oppIdvsOLIIdMap = new Map<Id, Id>();
	Map<ID, Opportunity> oppWithOppLineItemMap;
    List<Opportunity> oppList = new List<Opportunity>();
    List<OpportunityLineItem> oppLI = new List<OpportunityLineItem>();
    Id cid;
    String status;
    String connectionName;
        
    for(ID connId :connMap.keySet()){
			cid = connMap.get(connId).ID;
            status = connMap.get(connId).ConnectionStatus;
            connectionName = connMap.get(connId).ConnectionName;
		}
        
        //Populate a map of Opp Ids and OppLineItems
        
        for(OpportunityLineItem oppLineRecord: oppLI){
            if(oppLineRecord.Id == '00k1Q00003ZzlgO' ){
               oppIdvsOLIIdMap.put(oppLineRecord.ID, oppLineRecord.OpportunityId);
            }
        }
        
        if(oppIdvsOLIIdMap.keyset().size() > 0){
           
            for(Id oppId:oppIdvsOLIIdMap.keyset() ){
                Id opportunityId = oppIdvsOLIIdMap.get(oppId);
                prncList.add(new PartnerNetworkRecordConnection(
                ConnectionId = '04P1Q000000CaoyUAC',
                LocalRecordId = '04P3i000000004OEAQ',
                ParentRecordId = '0061Q00000oj1Dk',
                RelatedRecords = 'OpportunityLineItem'  
            //    prncList.add(newRecord);
                ));
                
            }
               
    for(PartnerNetworkConnection network: connectionList){
      Opportunity o = new Opportunity();
      PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
      newRecord.ConnectionId = network.Id;
      newRecord.LocalRecordId = '0061Q00000oj1Dk';
      newRecord.ParentRecordId = '0061Q00000oj1Dk';
      newRecord.RelatedRecords = 'OpportunityLineItem';   
      prncList.add(newRecord);
        
        
         }
            if(!prncList.isEmpty()){
        upsert prncList;
            }
        
    }
    
    }

}


Trigger

trigger S2SShareOppProds on OpportunityLineItem (after insert, after update) {
    
    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)){
    S2SForward.upsertOLI(trigger.new);
    }
}

 
  • September 09, 2019
  • Like
  • 0
Hello, I'm trying to create a soql query to pull account records that have a type of sub-customer. Additionally I'd like the accounts to not be linked to an association record  OR the accounts can be linked to a system record where the system record's server type is retired. Below is the following query I've created, but I get an error message of unexpected token: OR. Any help would be appreciated. 

SELECT Id, Name FROM Account WHERE Type = 'Sub-Customer'AND ID not IN (Select Account__c from Associations__c)
 OR ID IN SELECT Primary_Account__c, Server_Type__c from System__c where Server_Type__c == 'Retired'
  • August 30, 2019
  • Like
  • 0
Hello I am creating a REST api callout between two Salesforce instances in order to send opportunitiy records and their opportunity products. The current Salesforce to Salesforce functionality isn't allowing us to transfer more than one product for an opportunity. I am able to update the opportunity name using the workbench rest explorer, but I can't add or delete opportunity products. Any help with modifying my code to add or delete products would be appreciated. 

 
Rest Class

@RestResource(urlMapping='/Opportunities/*')
global with sharing class S2SOpp {

@HttpPut 
 //   global static List<Opportunity> upsertOpp(String name, String id){
      global static ID upsertOpp(String name, String id, String oppProductId, String oppProductName, Double quantity, Double unitprice,
                                Double listprice, Double totalprice, String product2Id, String opportunityId){
        HttpRequest req = new HttpRequest();
        req.setEndpoint('callout:S2S_Integration') ;
        req.setMethod('GET');
        Http http = new Http();
        HTTPResponse res = http.send(req);
        System.debug(res.getBody());
        List<Opportunity> listOpps = new List<Opportunity>();
        Set<Opportunity> setOpps = new Set<Opportunity>();
        Set<Id> ParentsIds = new Set<Id>();
        Set<OpportunityLineItem> setOli = new Set<OpportunityLineItem>();
        List<OpportunityLineItem> oli = [Select Id, OpportunityId from OpportunityLineItem where OpportunityId IN: listOpps];
        Map<Id, Opportunity> mapOpp = new Map<Id, Opportunity>([Select Id from Opportunity]);
        PriceBookEntry pbeEntry = new PriceBookEntry();
        List<PriceBookEntry> priceBookList = [Select Id, Product2Id, Product2.Id, Product2.Name 
                                             from PriceBookEntry where PriceBook2.isStandard = true];
       //  List<OpportunityLineItem> oppProds = new List<OpportunityLineItem>(OpportunityId = o.Id, PriceBookEntryId = pbeEntry.Id, Quantity = 1);
        for(Opportunity o: mapOpp.values()){
            
      
            for(OpportunityLineItem olis: o.opportunitylineitems){
                if(olis.Id != null){
                 listOpps.add(o);
                }
            }
            
        }
        RestRequest request = RestContext.request;
        PricebookEntry pbe = new PricebookEntry();
        Opportunity thisOpp = new Opportunity(Id = id, Name = name);
        OpportunityLineItem thisOLI = new OpportunityLineItem(Id = oppProductId, Quantity = 1, UnitPrice = unitprice, 
                                                              TotalPrice = totalprice, Product2Id = product2Id,
                                                             OpportunityId = opportunityId);
         
        
        upsert listOpps;
        upsert thisOpp;
        return thisOpp.Id;
    }
    
}



Workbench 

/services/apexrest/Opportunities/*

{
"name" : "Test",
"id" : "0061Q00000ohYrj",
"oppProductId" : "00k1Q00003ZzZbb",
"quantity" : "1.00",
"unitprice": "17.00",
"totalprice":  "17.00",
"product2Id" : "01t1Q000006nJn7",
"opportunityId" : "0061Q00000ohYrj"

}

 
  • August 26, 2019
  • Like
  • 0
Is it possible to connect two Salesforce instances using named credentials and password authentication for the authentication protocol instead of OAuth 2.0? I've read that when connecting between two Salesforce instances, password authentication won't work. Thank you. 
  • August 22, 2019
  • Like
  • 0
Hi, I have a class which loops through an account and then loops through all of the assets within that account to see if the assets have a certain status. I'm trying to use the contains method on the map of accounts but I'm getting the error message that the method doesn't exist or incorrect signature: void contains(boolean) from the type Map.Is there a way to search the status of the assets within an account to see if the status is present.? Thank you. 
 
public class AccountActiveProducts {

    
    public AccountActiveProducts(){
      List<Account> accountsToUpdate = new List<Account>();
      List<Account> oldAccountsToUpdate = new  List<Account>();
    }
   // public static void updateAccounts(List<SObject> assetLists, Map <Id, Account> AccountOldMap){   
  public static void updateAccounts(List<SObject> assetLists){
            List<Account> accountsToUpdate = new List<Account>();
            Set<String> setAssetsToRemove = new  Set<String>();
            List<String> listAssetsToRemove = new List<String>();
            Set<Id> ParentIds = new Set<Id>();
            for(Asset asset:(List<Asset>)assetLists){
                ParentIds.add(asset.AccountId); 
            }   
        
  //      for(Asset oldAsset:AccountOldMap){
            
  //      }
            Map<Id, Account> mapAccount = new Map<Id, Account>([Select Id, ProductsOwned__c,  (Select Id, ProductFamily__c, IsCompetitorProduct, Status from Assets Where  (Status != 'Retired' OR Status != 'Obsolete' OR Status != null)) From Account Where Id In: ParentIds]); 
          //  Map<Id, Account> mapAccountPurchased = new Map<Id, Account>([Select Id,  (Select Id, ProductFamily__c, Status from Assets Where  ( Status != null)) From Account Where Id In: ParentIds]);                                                   


       
            if(Trigger.isInsert || Trigger.isUpdate){ 
               for(Account ac : mapAccount.values()){
  
                   List<String> assetList = new List<String>();
                   Set<String> assetSet = new Set<String>();
                   Set<String> assetsPurchased = new Set<String>();
                   List<String> assetValues =  new List<String>();
                   for(Asset accountAsset: ac.assets){
                   if(accountAsset.Status != 'Retired' || accountAsset.Status != 'Obsolete'|| accountAsset.IsCompetitorProduct != true ){

                       assetSet.add(accountAsset.ProductFamily__c);
                       }
                       
                   
                       
                 //   if(accountAsset.Status == 'Retired' || accountAsset.Status == 'Obsolete' && (!ac.assets.contains(accountAsset.Status == 'Retired') || !ac.assets.contains(accountAsset.Status == 'Obsolete'))){
                 //    if(ac.assets.contains(accountAsset.status == 'Retired' || accountAsset.status == 'Obsolete' )
                       
              //         if(accountAsset.Status == 'Retired' || accountAsset.Status == 'Obsolete'|| accountAsset.IsCompetitorProduct == true){
                    
******* This is where I'm trying to search for the status. 

   if((accountAsset.Status == 'Retired' || accountAsset.Status == 'Obsolete'|| accountAsset.IsCompetitorProduct == true) &&  !(mapAccount.contains(accountAsset.Status == 'Installed' || accountAsset.Status == 'Registered' || accountAsset.Status == 'Shipped') )){
                          assetSet.remove(accountAsset.ProductFamily__c);
                       }
                       
                   }
                   assetList.addAll(assetSet);
                   assetList.sort();
                   String productFamily = string.join(assetList,', ' );
                   
                   if(ac.ProductsOwned__c != productFamily ){
                       ac.ProductsOwned__c = productFamily;
                       
                   accountsToUpdate.add(ac);
                   }
                   
               }
            
  
              //End of for loop above
              
          
               
               if(!accountsToUpdate.isEmpty()){
                   upsert accountsToUpdate;
               }
           }
            if(Trigger.isDelete){
                
                
            }
  
            }

}

 
  • August 08, 2019
  • Like
  • 0
Hello, I'm trying to create a test class for inserting/updating quote products. When I try to run a test class I get the error: System.NullPointerException: Attempt to de-reference a null object. The stack trace is Class.QuoteRollupPFBU.updateQuote: line 17, column 1
Class.QLITest.RollUpQLI: line 63, column 1. I thought I initalized all of the variables, but feel free to let me know if you see any errors in my code. Thank you. 
 
Class 

public class QuoteRollupPFBU {
    
       public QuoteRollupPFBU(){
      List<Quote> quotesToUpdate = new List<Quote>();
      List<QuoteLineItem> quoteLineItemToUpdate;
      quoteLineItemToUpdate = new List<QuoteLineItem>();
    }
        public static void updateQuote(List<SObject> quoteLineItemToUpdate){
            List<Quote> quotesToUpdate = new List<Quote>();
            Set<String> setQuoteProdsToRemove = new  Set<String>();
            List<String> listQuoteProdsToRemove = new List<String>();
            Set<Id> ParentIds = new Set<Id>();
            for(QuoteLineItem qProduct: (List<QuoteLineItem>)quoteLineItemToUpdate){
                System.debug( 'value :' + quoteLineItemToUpdate);
                ParentIds.add(qProduct.QuoteId); 
            }                                            
            Map<Id, Quote> mapQuote = new Map<Id, Quote>([Select Id, ProductBusinessUnits__c, RollupofProductFamilies__c,  (Select Id, QuoteId, ProductFamily__c, Product2Id, LineNumber, BusinessUnit__c from QuoteLineItems Where  (LineNumber != null) ) From Quote Where Id In: ParentIds]); 

           if(Trigger.isInsert || Trigger.isUpdate ){ 
               for(Quote q : mapQuote.values()){
  
                   List<String> quoteLineItemProductFamList = new List<String>();
                   List<String> quoteLineItemBUList = new List<String>();
                   Set<String> qliProdFamSet = new Set<String>();
                   Set<String> qliBUSet = new Set<String>();
                   
                   for(QuoteLineItem qli: q.quotelineitems){
                       if(qli.LineNumber != null  ){
                       qliProdFamSet.add(qli.ProductFamily__c);
                       qliBUSet.add(qli.BusinessUnit__c);   
                       }
                        else if(qli.LineNumber == null ){
                          qliBUSet.remove(qli.BusinessUnit__c);
                          qliProdFamSet.remove(qli.ProductFamily__c);
                           }
                           
                   }
                       
                   
                   quoteLineItemProductFamList.addAll(qliProdFamSet);
                   quoteLineItemProductFamList.sort();
                   String productFamily = string.join(quoteLineItemProductFamList,', ' );
                   
                   quoteLineItemBUList.addAll(qliBUSet);
                   quoteLineItemBUList.sort();
                   String businessUnit = string.join(quoteLineItemBUList,', ' );
                   
                   if(q.RollupofProductFamilies__c != productFamily &&  q.ProductBusinessUnits__c != businessUnit ){
                       q.RollupofProductFamilies__c = productFamily;
                        q.ProductBusinessUnits__c = businessUnit;
                   quotesToUpdate.add(q);
                   }
                                     
               }
              //End of for loop above
               
               if(!quotesToUpdate.isEmpty()){
                   upsert quotesToUpdate;
               }
           }
         
                       }
  
            }




Test Class 

@isTest(SeeAllData = true)
public class QLITest {
    
          @isTest static void RollUpQLI(){
       List<QuoteLineItem> listQLI = new List<QuoteLineItem>();
       List<Quote> quotesToUpdate = new List<Quote>();
       Set<Id> ParentIds = new Set<Id>();
      
      
       //Insert product
       Product2 p = new Product2(Name = 'Test Name', BusinessUnit__c = 'CDS', ProductFamily__c = 'Communication Director');   
       insert p;
       //Insert pricebook
       Pricebook2 standardPricebook = new Pricebook2(Id = Test.getStandardPricebookId(), IsActive = true);
       update standardPricebook;
      // Id pricebookId = Test.getStandardPricebookId();
       
       PricebookEntry pbe1 = new PricebookEntry(Pricebook2id = standardPricebook.Id, Product2id=p.Id, isActive = true, unitPrice=100);
       insert pbe1;
              
        Opportunity o = new Opportunity(Pricebook2id = Test.getStandardPricebookId(), Name = 'Test Opp1', RollupofProductFamilies__c = 'Test', ProductBusinessUnits__c = 'Bed Stat', StageName ='Test Stage', CloseDate = date.today());
        insert o;  
        Quote q = new Quote(OpportunityId = o.Id, Name = 'Test Quote', Pricebook2Id = standardPricebook.Id);   
        insert q;
              
       QuoteLineItem oli = new QuoteLineItem(PricebookEntryid = pbe1.Id, ProductFamily__c = 'Bed Stat', QuoteId = q.Id, Product2Id = p.Id, Quantity = 1, UnitPrice = 1); 
       insert oli;
        listQLI.add(oli);
        upsert listQLI;
        ParentIds.add(oli.QuoteId);
        Map<Id, Quote> mapQuote = new Map<Id, Quote>([Select Id, BusinessUnit__c, ProductBusinessUnits__c, RollupofProductFamilies__c, (Select Id, QuoteId, Product2Id, LineNumber, ProductFamily__c,  BusinessUnit__c from QuoteLineItems ) From Quote Where Id In: ParentIds]);                                                   

        for(Quote quote: mapQuote.values()){
             List<String> qliProdFamList = new List<String>();
             Set<String> qlitProdFamSet = new Set<String>();
             Set<String> qlitBUset = new Set<String>();
             List<String> qliBUList = new List<String>();
              for(QuoteLineItem ql: quote.QuoteLineItems){
                       
                       qlitProdFamSet.add(ql.ProductFamily__c);
                       qlitBUset.add(ql.BusinessUnit__c);

                   }
                   qliProdFamList.addAll(qlitProdFamSet);
                   qliProdFamList.sort();
                   String productFamily = string.join(qliProdFamList,', ' );
            
                   qliBUList.addAll(qlitBUset);
                   qliBUList.sort();
                   String bizUnit = string.join(qliBUList,', ' );
            if(quote.RollupofProductFamilies__c != productFamily && quote.BusinessUnit__c != bizUnit){
                 quote.RollupofProductFamilies__c = productFamily;
                 quote.ProductBusinessUnits__c = bizUnit;
                   quotesToUpdate.add(quote);
                   }
        }
        upsert quotesToUpdate;
             
        
        test.startTest();
    //    if(quotesToUpdate.size()>0 && listQLI.size()>0){
         
         QuoteRollupPFBU.updateQuote(listQLI);
  //      }
        test.stopTest();
       
    }
    
    


}


Trigger

trigger PrimaryQliTrigger on QuoteLineItem (before insert, before update, after insert, after update, before delete, after delete) {
    
        if(Trigger.isBefore){
        if(Trigger.isInsert){   
        }
        if(Trigger.isUpdate){
                    }
        if(Trigger.isDelete){
                    }
    }
    
 if(Trigger.isAfter){
        if(Trigger.isInsert){ 
             QuoteRollupPFBU.updateQuote(trigger.new);
        }
       if(Trigger.isUpdate || Trigger.isInsert ){
       //    QuoteRollupPFBU.updateQuote(trigger.new);
                    }
        if(Trigger.isDelete){
                    }
    }    


    
    

}

 
  • May 22, 2019
  • Like
  • 0
Hello all, 

I am trying to correct an error in  my test class which states 'System.NullPointerException: Attempt to de-reference a null object'. The two lines where I'm receiving error are in the test class -  AccountActiveProducts.updateAccounts(listAssets); and in the class 
 List<Account> accountsToUpdate = new List<Account>();
Which object isn't being instantiated? Below are the classes. Thank you for your help. 

Test Class 

@isTest 

public class AccountActiveProductsTest {
    
    @isTest static void RollupAsset(){
        List<Asset> listAssets = new List<Asset>();
        Set<String> assetSet = new Set<String>();
        Account aTest = new Account(name='Test Acct', billingcity='test', billingstate='Maryland');
        insert aTest;
        //create asset
        Asset asset = new Asset(name = 'Asset 1', AccountId = aTest.Id, ProductFamily__c = 'Bed Stat', Status = 'Shipped' );
        insert asset;
        List<Account> listAccounts = new List<Account>();
        List<Account> listAccountstoUpdate = new List<Account>();
        
        Integer numAssets;
        for(Integer i=0; i<200; i++){
            Asset ast = new Asset(Name = 'Test Asset' + i, AccountId = aTest.Id, ProductFamily__c = 'Bed Stat', Status = 'Shipped');
               if(ast.Status != 'Retired' || ast.Status != 'Obsolete'){
            assetSet.add(ast.ProductFamily__c);
        }
            listAssets.add(ast);
          
        }
        insert listAssets;
        
        Set<Id> ParentIds = new Set<Id>();
        ParentIds.add(asset.AccountId);
        
        assetSet.add(asset.ProductFamily__c);
        
        listAccounts.add(aTest);
        Map<Id, Account> mapAccount = new Map<Id, Account>([Select Id, ProductsOwned__c, (Select Id, ProductFamily__c, Status from Assets Where  (Status != 'Retired' OR Status != 'Obsolete' OR Status != null)) From Account Where Id In: ParentIds]);  
        List<String> assetList = new List<String>();
        assetList.addAll(assetSet);
        test.startTest();
        AccountActiveProducts aap  = new AccountActiveProducts();
        listAssets.add(asset);
        asset.ProductFamily__c = 'Communication Director';
       String productFamily = string.join(assetList,', ' );
           if(aTest.ProductsOwned__c != productFamily){
                       aTest.ProductsOwned__c = productFamily;
                   listAccountstoUpdate.add(aTest);
                   }
        
          if(!listAccountstoUpdate.isEmpty()){
                   upsert listAccountstoUpdate;
               }
       
        if(listAssets.size() > 0){
             update listAssets;
       AccountActiveProducts.updateAccounts(listAssets);
        }
        upsert listAccounts;
        test.stopTest();
    }

}

Class

public class AccountActiveProducts {
    
        public static void updateAccounts(List<Asset> assetLists){
            Set<String> setAssetsToRemove = new  Set<String>();
            List<String> listAssetsToRemove = new List<String>();
            Set<Id> ParentIds = new Set<Id>();
            for(Asset asset:assetLists){
                ParentIds.add(asset.AccountId); 
            }                                            
            Map<Id, Account> mapAccount = new Map<Id, Account>([Select Id, ProductsOwned__c, (Select Id, ProductFamily__c, Status from Assets Where  (Status != 'Retired' OR Status != 'Obsolete' OR Status != null)) From Account Where Id In: ParentIds]);                                                   

            List<Account> accountsToUpdate = new List<Account>();
   
           
            
           if(Trigger.isInsert || Trigger.isUpdate){ 
               for(Account ac : mapAccount.values()){
  
                   List<String> assetList = new List<String>();
                   Set<String> assetSet = new Set<String>();
                   
                   for(Asset accountAsset: ac.assets){
                       if(accountAsset.Status != 'Retired' || accountAsset.Status != 'Obsolete' ){
                       assetSet.add(accountAsset.ProductFamily__c);
                       }
                       
                       if(accountAsset.Status == 'Retired' || accountAsset.Status == 'Obsolete'){
                          
                          assetSet.remove(accountAsset.ProductFamily__c);
                       }
                       
                   }
                   assetList.addAll(assetSet);
                   assetList.sort();
                   String productFamily = string.join(assetList,', ' );
                   
                   if(ac.ProductsOwned__c != productFamily){
                       ac.ProductsOwned__c = productFamily;
                   accountsToUpdate.add(ac);
                   }
               }
               
              //End of for loop above
              
          
               
               if(!accountsToUpdate.isEmpty()){
                   upsert accountsToUpdate;
               }
           }
            
  
            }

}
  • April 30, 2019
  • Like
  • 0
Hello I am trying to add additional string elements to my set<string> collection variable. When I add a new string element (e.g. asset), it seems to be overriding the existing values in the assetCollection variable. Is there a way to add the additonal elements without overiding existing values? 

I've tried the add(string element) method that doesn't seem to be working. Thank you. 

Below are my class and trigger 

Class 

public class AccountActiveProducts {
    
        public static void updateAccounts(List<Asset> assetLists){
                                            
            Map<Id, Account> mapAccount = new Map<Id, Account>([Select Id, ProductsOwned__c, (Select Id, ProductFamily__c from Assets Where Id In: Trigger.new) From Account]);                                                   
            Set<String> assetCollection = new Set<String>();
            Set<Id> ParentIds = new Set<Id>();
            List<Account> AccountParent = new List<Account>();
            String a = '';
            Boolean noMatch = false;
           if(Trigger.isInsert || Trigger.isUpdate){ 
                   
                for(Asset asset: assetLists){
                   if(asset.Status!= null ||asset.Status !='Retired' || asset.Status!= 'Obsolete' && asset.AccountId != null )  
                   ParentIds.add(asset.AccountId);
                   assetCollection.add(asset.ProductFamily__c);
                }     
            }
            
               if(Trigger.isDelete){ 
                   
                for(Asset assetOld: assetLists){
                   if(assetOld.Status!= null && assetOld.Status !='Retired' && assetOld.Status!= 'Obsolete' && assetOld.AccountId != null )  
                   ParentIds.add(assetOld.AccountId);
                }     
            }
            
            for(Account account: [Select Id, ProductsOwned__c from Account where Id In: ParentIds]){
                
                a =+ '' + string.valueOf(assetCollection);
                mapAccount.put(account.id, account);
                
            }
            
            if(ParentIds.size() >0){
                
                List<Asset> assetList = new List<Asset>([Select Id, AccountId, Status, ProductFamily__c from Asset where
                                                        AccountId IN: ParentIds]);
                List<Account> accountList = new List<Account>([Select Id, ProductsOwned__c from Account where
                                                        Id IN: ParentIds]);
                
                               
                for(Account accountP: accountList){
         
                    for(Asset asstc: assetList){
                        if(asstc.AccountId == accountP.Id)
                        
                          for(String s: assetCollection){
                              //If assetCollection doesn't contain the string element, then add that string element to the collection
                              if(!assetCollection.contains(s) && asstc.Status!= null && asstc.Status !='Retired' && asstc.Status!= 'Obsolete' && assetCollection.isEmpty()){
                                  noMatch = false;
                              assetCollection.add(asstc.ProductFamily__c); 
                      //           assetCollection.add(s); 
                                 String outputString = String.join(new List<String>(assetCollection), ',');
                               a =+  string.valueOf(assetCollection).replaceAll('[{||}]','') + ', ' + asstc.ProductFamily__c;
                       //          a =+  outputString.replaceAll('[{||}]','');
                              }
                              else if(assetCollection.contains(s) && asstc.Status!= null && asstc.Status !='Retired' && asstc.Status!= 'Obsolete' && assetCollection.contains(asstc.ProductFamily__c)){
                                  noMatch = true;
                                  
                                  String outputString = String.join(new List<String>(assetCollection), ',');
                                  a =  string.valueOf(assetCollection).replaceAll('[{||}]','');
                              }
                              
                                  else if(asstc.Status =='Retired' || asstc.Status== 'Obsolete' || asstc.Status== null &&  assetCollection.contains(asstc.ProductFamily__c)){
                                  noMatch = false;
                                  assetCollection.remove(asstc.ProductFamily__c);
                              }
                           
                    }
                        
                    }
              
                    accountP.ProductsOwned__c = a;
                    
                }
                
                try{
                    upsert accountList;
                }
                
                catch(Exception ex){
                    System.debug('Exception is ' + ex);
                    
                }            
            }        
            }
}


Trigger 

trigger AssetPrimaryTrigger on Asset (before insert, before update, after insert, after update, before delete, after delete) {
    if(Trigger.isBefore){
        if(Trigger.isInsert){   
        }
        if(Trigger.isUpdate){
                    }
        if(Trigger.isDelete){
                    }
        
    }
    
 if(Trigger.isAfter){
        if(Trigger.isInsert){ 
           
        }
        if(Trigger.isUpdate){
             AccountActiveProducts.updateAccounts(trigger.new);
                    }
        if(Trigger.isDelete){
                    }
        
    }    
    

}
  • April 22, 2019
  • Like
  • 0
Hello I would like to rollup a field value from all of the assets on an account up to that account's field. Currently, the trigger is updating the account field, but it's overwriting the existing value, and not collecting the asset field values. On line 24 I'm getting an error of illegal assignment from set to string (ProductsOwned_c += prodFam.clone()). 

I'm trying to take all of the unique string values in the ProdFam set variable and load them into the ProductsOwned__ field. Can I load a collection into a text field? Thank you for your help.  

trigger BulkifyAssets on Asset (before insert, before update) {
    Set<Id> accountId = new Set<Id>();
    Map<Id, Account> parentRecords = new Map<Id, Account>();
    Map<String,Account> accProductsOwnedMap = new Map<String,Account>();
    Set<String> prodFam = new Set<String>();
   
for(Asset a: trigger.new){
    if(a.Status != null || a.status != 'Retired' || a.status != 'Obsolete' )
    accountId.add(a.AccountId);
    accountId.remove(null);
    String prodFamAccount = a.ProductFamily__c;
    prodFam.add(prodFamAccount);
   
   
    for(Id parentId: accountId){
        String prodFamSingle;
       
        for(String f: prodFam)
                    parentRecords.put(parentId, new Account(Id = parentId, ProductsOwned__c =+ prodFam.clone()));
 
       
        for(Asset asset: [Select Id, ProductFamily__c, AccountId from Asset Where Id In: accountId]){
           if(parentRecords.get(asset.AccountId).ProductsOwned__c != null){
           parentRecords.get(asset.AccountId).ProductsOwned__c += ',' + parentRecords.values();
        }
        else{
     parentRecords.get(asset.AccountId).ProductsOwned__c += ',' + parentRecords.values();             
        }
        }
   
    if(parentRecords.size()>0)
    {
   update parentRecords.values();
}  
}
}
}
 
  • April 11, 2019
  • Like
  • 0
Hello, I have a flow that loops through assets on an account. When I try to do a mass update manually from an asset list view, I get the 'maximum number of duplicate updates in one batch (12 allowed)' when updating more than 12 assets on an account. 

In the flow I have a loop element, and any items that meet certain criteria are directed to the update element. The update elemnt is where I receive the error whenever I update more than 12 records on the same account. 

Is there a way to bulkify this? Would I need an apex trigger in addition to this flow? Thank you.  
  • March 11, 2019
  • Like
  • 0
Hello I'm looking to display a list of cases for our community users. I would like to display the cases for the contact (community user) where even though they may not be a contact on the case, they are a related contact of the account to which the case refers to.

So for Case ABC that is related to the account: Test Account, if the contact is a related contact on Test Account, then they should be able to view Case ABC. 

I tried to create a list of accounts and cases but it's not filtering filtering the cases by contact. Thank you for your help. 

String userEmail = UserInfo.getUserEmail();
        list<account> listaccounts = [SELECT ID, Name, (SELECT name,AccountId, Contact.FirstName, Contact.Email, Contact.LastName FROM Contacts Where Contact.Email != Null AND Contact.Email =: userEmail AND Contact.Email = 'guestadmin@time.com' ) FROM Account ];     
        
        list<case> myCases = [select id, casenumber, AccountId,  subject, status, priority, createddate, closeddate from case Where  AccountId =: listaccounts ];
 
  • February 18, 2019
  • Like
  • 0
Hello, we have an installed package and I am trying to authenticate with it from Salesforce. The third-party provided me  with the client Id and cliente secret. I am trying to initiate post from workbench with the following JSON body. However I'm confused as to which service URI I should use in workbench's URI?

headers: Accept: 'application/json', Content-Type: application/json uri: https://thirdparty.com method: POST json: { "session_id": [Salesforce session], "api_url": [Salesforce Partner WSDL SOAP endpoint for the Org], "client_id": [client id passed to the authorization endpoint], "client_secret": [client secret pair for the client id] }

Thank you. 
  • February 05, 2019
  • Like
  • 0
Hello, our Organization-wide default settings for accounts and leads is private. I would like to create a solution where if the Account Name matches the Lead Company name, then the Account Owner can edit that lead record. I've tried using code that I found on this forum to update a custom checkbox field if the Account Name and Lead Company match. The issue I'm running into is when I create the Lead sharing rule in settings, I can't specify record access by user, but rather only by group. Is there a way to specify it by Account owner? Thank you

trigger LeadMatch on Lead (before insert,before update) {
    
    List<Account> accList = [Select Id,Name from Account];
    
    for(Lead lead : trigger.new){
        lead.LeadAccountMatch__c = false;
        for(Account acc: accList){
            if(lead.Company == acc.Name && lead.OwnerId != acc.OwnerId){
                lead.LeadAccountMatch__c = true;
                break;
            }
        }        
    }
  • January 29, 2018
  • Like
  • 0
Hello, I'm attempting to override the field color  label for certain fields on the standard contracts object. Can I can do this by inputting code within the <apex:detail attribute or should I not use the <apex:detail attribute and manually type out each field I want to include? The code I have below is what I've tried so far. Thank you for your help. 

<apex:page standardController="Contract">
    <style type="text/css">
    
    blueText{color:blue;}
    
    </style>
    
    
<apex:form >
    <apex:pageBlock>
<apex:pageBlocksection title="Contract Details Test" columns="2">   
  <apex:detail subject="{!contract.Id}" >
      <apex:outputLabel >LA</apex:outputLabel>
      <apex:outputField label="Status" value="{!contract.Status}" />
      <apex:inputField value="{!contract.Status}" label="{contract.Status} "/>
      
      
    </apex:detail> 
        </apex:pageBlocksection>
   </apex:pageBlock>
    </apex:form>    
    
</apex:page>
  • November 30, 2017
  • Like
  • 0
Hello,

I am attempting to run an apex test class to deploy the changes to our production org. I would like to setup a test to insert an opportunity as well as the opportunity products. I get the error below that the TotalPrice field is required even though I've included it in my code. Are there any other fields that I am missing? 

Thank you for your help

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: TotalPrice (total price must be specified): [TotalPrice]
  Opportunity o = new Opportunity(Name = 'Test Opportunity', AccountId = a.Id, CloseDate = Date.today(), StageName = 'Prospecting', Maintenance_Type__c = 'Standard Maintenance', Competitors__c = 'Test' );
        if (isSandbox) 
        o.Pricebook2Id = defaultPB.Id;
        insert(o);

    List<OpportunityLineItem> items = new List<OpportunityLineItem>();
        for (PricebookEntry pbe: products)
        {
            OpportunityLineItem temp = new OpportunityLineItem();
            temp.OpportunityId = o.Id;
            temp.PricebookEntryId = pbe.Id;
            temp.Quantity = 3;
            
            //temp.UnitPrice = 100;
            temp.TotalPrice = 0; 
           
            items.add(temp);
      
        }
  • October 19, 2017
  • Like
  • 0
Hello I am trying to add opportunity products to my opportunity when I share my opportunity records with my target org. This trigger to be on the target org. Right now I believe the code is only setup to include one product per opportunity, but some opportunuties may have two products.  One error that I'm getting is: List has more than 1 row for assignment to SObject.

Below is my code. Thank you for your help.

trigger OppProduct3 on Opportunity (after insert) {

    List<Pricebook2> pbe = [SELECT id from Pricebook2 Where Name = 'Test Pricebook 7-17'];

      If(Trigger.isAfter){
          
    OpportunityLineItem[] lines = new OpportunityLineItem[0];
          
PricebookEntry entry = [SELECT ID From PricebookEntry Where Pricebook2Id = '01s8E000000IU4C' AND Product2.ProductCode = 'DEFAULT'   ];
        
        set<ID> FinalOptyIds = new set<id>();
          
          List<PartnerNetworkRecordConnection> ConListOpty = new List<PartnerNetworkRecordConnection>([select Id, ConnectionId, PartnerRecordId, LocalRecordId from PartnerNetworkRecordConnection
                                                                                                     where LocalRecordId in :Trigger.newmap.keyset() AND (Status ='Sent' OR Status = 'Received') AND ConnectionId='04P8E000000CaSKUA0']);
        system.debug('ConListOpty-----' + ConListOpty);
        
        If(!ConListOpty.IsEmpty()){
            
            for(PartnerNetworkRecordConnection op : ConListOpty){
                if(op.LocalRecordId != null){
                    FinalOptyIds.add(op.LocalRecordId);
                }
                system.debug('FinalOptyIds-----' + FinalOptyIds);
            }
        }
          
          If(!pbe.IsEmpty()){
          
          for(Opportunity record: Trigger.new){
              lines.add(new OpportunityLineItem(PricebookEntryId = entry.Id, OpportunityId = record.Id, Quantity =1));
              
          }
         insert lines;
          }
          
      }
}
  • August 13, 2017
  • Like
  • 0
I  have a salesforce to salesforce connection and I would like to be able to send both the opportunity and related opportunity products without having to manually accept them in the target org. According to salesforce documentation, if the auto-accept on opportunities is turned on, then opportunity products can't be shared. 

Is there a way to bypass this with an apex batch job perhaps (mass auto accept)?

Thank you
  • August 09, 2017
  • Like
  • 0
Hello, I have a SOAP callout to an external webservice and I'd like to retrieve the records from the external service and insert them into Salesforce. If I query on a specific record from the external system, I can insert that record into Salesforce. However when I query on multiple records, they're not being inserted into SF. I tried creating a while loop and adding the records to a list and then insert the list, but that hasn't worked. Any help would be appreciated. Thank you.
 
public class ListOutboundFax {
    
      public static void getListOutBoundRecords(Integer customerId ){     
        Concord__c con = new Concord__c();
        List<Concord__c> lstConcord = new  List<Concord__c>();
        
        accountmanagementreportingwebservice.AccountManagementReportingWebserviceSoap s= new accountmanagementreportingwebservice.AccountManagementReportingWebserviceSoap();
        accountmanagementreportingwebservice.ListOutboundActivityRequest  req = new accountmanagementreportingwebservice.ListOutboundActivityRequest();
        accountmanagementreportingwebservice.ListOutboundActivityResponse res = new accountmanagementreportingwebservice.ListOutboundActivityResponse();
        accountmanagementreportingwebservice.Authentication a =new accountmanagementreportingwebservice.Authentication();
        accountmanagementreportingwebservice.ArrayOfString filter = new accountmanagementreportingwebservice.ArrayOfString();
        accountmanagementreportingwebservice.Filter filters = new accountmanagementreportingwebservice.Filter();
        
                   
        a.Username = '-------';
        a.Password = '-------'; 
        req.Authentication = a;
        req.CustomerId = customerId;
        req.EndDate = date.valueOf('2019-11-12T06:03:15-08:00');
        req.ExcludeSubLevelEntries = Boolean.valueOf('true');
        req.PageIndex = 0;
        req.PageSize = 100;
        req.SortOption = 0;
        req.StartDate = date.valueOf('2019-11-11T06:03:15-08:00');
        
        res = s.ListOutboundActivity(req);
        String jsonResponse = (JSON.serializePretty(res));
    
        System.debug(jsonResponse);
   Integer count = 0;     
   JSONParser parser = JSON.createParser(jsonResponse);
          while(parser.nextToken() != null && count < lstConcord.size()){
              if(parser.getCurrentToken() == JSONToken.FIELD_NAME){
               parser.nextValue();
                if(parser.getCurrentName() == 'id') {
                   con.JOB_ID__c = parser.getText(); 
    //               System.debug(con.Name);
                }
                  
                 else if(parser.getCurrentName() == 'dur'){
                            con.Duration__c = Integer.valueOf(parser.getText());
    //                        System.debug(con.Duration__c);

                        }
                        
                        else if(parser.getCurrentName() == 'pgct'){
                            con.Delivered_Pages__c = Integer.valueOf(parser.getText());
    //                        System.debug(con.Delivered_Pages__c);
                        }
                        
                        else if(parser.getCurrentName() == 'dt'){
                            con.Stop_Date__c = Date.valueOf(parser.getText());
  //                          System.debug(con.Stop_Date__c);
                        }
                        
                        else if(parser.getCurrentName() == 'FaxNumber'){
                            con.Fax__c = parser.getText();
 //                           System.debug(con.Fax__c);
                        }  
                  
                   else if(parser.getCurrentName() == 'fcc'){
                            con.Sender_Country__c = parser.getText();
   //                         System.debug(con.Sender_Country__c);
                        } 
                  
                  else if(parser.getCurrentName() == 'cid'){
                            con.Concord_Account_ID__c = parser.getText();
    //                        System.debug(con.Concord_Account_ID__c);
                        } 
                  

                  lstConcord.add(con);
                  System.debug('Size of List' + lstConcord.size());
              }  
              
              System.debug('Size of List' + lstConcord.size());
              count++;
              
              
          }
  
                        if(lstConcord.size() > 0 ){
            try{
                
                insert lstConcord;
            }
            
            catch(Exception ex){
                System.debug(ex);
            }
        }
          
          
          
              }
          }

 
  • November 13, 2019
  • Like
  • 0
Hello, I'm looking to create a component that fires an action (i.e. popup modal) if a custom account check box is populated. I have the  popup box appearing if I click on the account's 'edit' button which I overrode, but I'd like to create an 'if' condition. Any help would be appreciated. Thank you. 

Component
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,lightning:actionOverride,force:hasRecordId,force:lightningQuickAction" access="global" >
	
    <aura:attribute name="isModalOpen" type="boolean" default="false"/>
    <aura:attribute name="AOff" type="Account" default="{'sobjectType': 'Account'
                                                        'Offsite_Data_Transfer_Prohibited__c': false}"/>
   
 <!--   <lightning:button variant="brand" label="Override" onclick="{!c.handleModal}" /> -->
    
    
    <force:recordData aura:id="forceRecord"
                recordId="{!v.recordId}"
                targetRecord="{!v.forceRecord}"
                targetFields="{!v.AOff}"
                fields="Id,Offsite_Data_Transfer_Prohibited__c"
                mode="EDIT" />
    
    <aura:handler name="init" value="{!this}" action="{!c.handleModal}" ></aura:handler>
    
  
    <div class="slds-m-around_xx-large">
        
        <!--
        <lightning:button variant="brand"
                          label="What is Modal/PopUp Box?"
                          title="What is Modal/PopUp Box?"
                          onclick="{! c.openModel }" />  -->
    
    <!--Use aura:if tag to display/hide popup based on isModalOpen value-->  
        <aura:if isTrue="{!v.isModalOpen}">
    
     <!-- Modal/Popup Box starts here-->
            <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">


 <div class="slds-modal__container">
                    <!-- Modal/Popup Box Header Starts here-->
                    <header class="slds-modal__header">
                        <lightning:buttonIcon iconName="utility:close"
                                              onclick="{! c.closeModel }"
                                              alternativeText="close"
                                              variant="bare-inverse"
                                              class="slds-modal__close"/>



 <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">OffSite Data Transfer Prohibited</h2>
                    </header>


 <!--Modal/Popup Box Body Starts here-->
                    <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                        <p><b>The transfer of data offiste for this account is prohibited. 
                            </b>
                        </p>
                    </div>

<!--Modal/Popup Box Footer Starts here-->
                    <footer class="slds-modal__footer">
                        <lightning:button variant="neutral"
                                          label="Cancel"
                                          title="Cancel"
                                          onclick="{! c.closeModel }"/>
                        <lightning:button variant="brand"
                                          label="OK"
                                          title="OK"
                                          onclick="{!c.submitDetails}"/>
                    </footer>
                </div>
            </section>
            <div class="slds-backdrop slds-backdrop_open"></div>
        </aura:if>
    </div>
    
</aura:component>

Controller 
 
({
    handleModal: function(component, event, helper) {
       
        // Set isModalOpen attribute to true
    
      component.set("v.isModalOpen", true);
    },
    
      closeModel: function(component, event, helper) {
      // Set isModalOpen attribute to false  
      component.set("v.isModalOpen", false);
   },
    
    
   submitDetails: function(component, event, helper) {
      // Set isModalOpen attribute to false
      //Add your code to call apex method or do some processing
      component.set("v.isModalOpen", false);
   }
    
    
    
})

 
  • October 27, 2019
  • Like
  • 0
Is it possible to connect two Salesforce instances using named credentials and password authentication for the authentication protocol instead of OAuth 2.0? I've read that when connecting between two Salesforce instances, password authentication won't work. Thank you. 
  • August 22, 2019
  • Like
  • 0
Hi, I have a class which loops through an account and then loops through all of the assets within that account to see if the assets have a certain status. I'm trying to use the contains method on the map of accounts but I'm getting the error message that the method doesn't exist or incorrect signature: void contains(boolean) from the type Map.Is there a way to search the status of the assets within an account to see if the status is present.? Thank you. 
 
public class AccountActiveProducts {

    
    public AccountActiveProducts(){
      List<Account> accountsToUpdate = new List<Account>();
      List<Account> oldAccountsToUpdate = new  List<Account>();
    }
   // public static void updateAccounts(List<SObject> assetLists, Map <Id, Account> AccountOldMap){   
  public static void updateAccounts(List<SObject> assetLists){
            List<Account> accountsToUpdate = new List<Account>();
            Set<String> setAssetsToRemove = new  Set<String>();
            List<String> listAssetsToRemove = new List<String>();
            Set<Id> ParentIds = new Set<Id>();
            for(Asset asset:(List<Asset>)assetLists){
                ParentIds.add(asset.AccountId); 
            }   
        
  //      for(Asset oldAsset:AccountOldMap){
            
  //      }
            Map<Id, Account> mapAccount = new Map<Id, Account>([Select Id, ProductsOwned__c,  (Select Id, ProductFamily__c, IsCompetitorProduct, Status from Assets Where  (Status != 'Retired' OR Status != 'Obsolete' OR Status != null)) From Account Where Id In: ParentIds]); 
          //  Map<Id, Account> mapAccountPurchased = new Map<Id, Account>([Select Id,  (Select Id, ProductFamily__c, Status from Assets Where  ( Status != null)) From Account Where Id In: ParentIds]);                                                   


       
            if(Trigger.isInsert || Trigger.isUpdate){ 
               for(Account ac : mapAccount.values()){
  
                   List<String> assetList = new List<String>();
                   Set<String> assetSet = new Set<String>();
                   Set<String> assetsPurchased = new Set<String>();
                   List<String> assetValues =  new List<String>();
                   for(Asset accountAsset: ac.assets){
                   if(accountAsset.Status != 'Retired' || accountAsset.Status != 'Obsolete'|| accountAsset.IsCompetitorProduct != true ){

                       assetSet.add(accountAsset.ProductFamily__c);
                       }
                       
                   
                       
                 //   if(accountAsset.Status == 'Retired' || accountAsset.Status == 'Obsolete' && (!ac.assets.contains(accountAsset.Status == 'Retired') || !ac.assets.contains(accountAsset.Status == 'Obsolete'))){
                 //    if(ac.assets.contains(accountAsset.status == 'Retired' || accountAsset.status == 'Obsolete' )
                       
              //         if(accountAsset.Status == 'Retired' || accountAsset.Status == 'Obsolete'|| accountAsset.IsCompetitorProduct == true){
                    
******* This is where I'm trying to search for the status. 

   if((accountAsset.Status == 'Retired' || accountAsset.Status == 'Obsolete'|| accountAsset.IsCompetitorProduct == true) &&  !(mapAccount.contains(accountAsset.Status == 'Installed' || accountAsset.Status == 'Registered' || accountAsset.Status == 'Shipped') )){
                          assetSet.remove(accountAsset.ProductFamily__c);
                       }
                       
                   }
                   assetList.addAll(assetSet);
                   assetList.sort();
                   String productFamily = string.join(assetList,', ' );
                   
                   if(ac.ProductsOwned__c != productFamily ){
                       ac.ProductsOwned__c = productFamily;
                       
                   accountsToUpdate.add(ac);
                   }
                   
               }
            
  
              //End of for loop above
              
          
               
               if(!accountsToUpdate.isEmpty()){
                   upsert accountsToUpdate;
               }
           }
            if(Trigger.isDelete){
                
                
            }
  
            }

}

 
  • August 08, 2019
  • Like
  • 0
Hello, I'm trying to create a test class for inserting/updating quote products. When I try to run a test class I get the error: System.NullPointerException: Attempt to de-reference a null object. The stack trace is Class.QuoteRollupPFBU.updateQuote: line 17, column 1
Class.QLITest.RollUpQLI: line 63, column 1. I thought I initalized all of the variables, but feel free to let me know if you see any errors in my code. Thank you. 
 
Class 

public class QuoteRollupPFBU {
    
       public QuoteRollupPFBU(){
      List<Quote> quotesToUpdate = new List<Quote>();
      List<QuoteLineItem> quoteLineItemToUpdate;
      quoteLineItemToUpdate = new List<QuoteLineItem>();
    }
        public static void updateQuote(List<SObject> quoteLineItemToUpdate){
            List<Quote> quotesToUpdate = new List<Quote>();
            Set<String> setQuoteProdsToRemove = new  Set<String>();
            List<String> listQuoteProdsToRemove = new List<String>();
            Set<Id> ParentIds = new Set<Id>();
            for(QuoteLineItem qProduct: (List<QuoteLineItem>)quoteLineItemToUpdate){
                System.debug( 'value :' + quoteLineItemToUpdate);
                ParentIds.add(qProduct.QuoteId); 
            }                                            
            Map<Id, Quote> mapQuote = new Map<Id, Quote>([Select Id, ProductBusinessUnits__c, RollupofProductFamilies__c,  (Select Id, QuoteId, ProductFamily__c, Product2Id, LineNumber, BusinessUnit__c from QuoteLineItems Where  (LineNumber != null) ) From Quote Where Id In: ParentIds]); 

           if(Trigger.isInsert || Trigger.isUpdate ){ 
               for(Quote q : mapQuote.values()){
  
                   List<String> quoteLineItemProductFamList = new List<String>();
                   List<String> quoteLineItemBUList = new List<String>();
                   Set<String> qliProdFamSet = new Set<String>();
                   Set<String> qliBUSet = new Set<String>();
                   
                   for(QuoteLineItem qli: q.quotelineitems){
                       if(qli.LineNumber != null  ){
                       qliProdFamSet.add(qli.ProductFamily__c);
                       qliBUSet.add(qli.BusinessUnit__c);   
                       }
                        else if(qli.LineNumber == null ){
                          qliBUSet.remove(qli.BusinessUnit__c);
                          qliProdFamSet.remove(qli.ProductFamily__c);
                           }
                           
                   }
                       
                   
                   quoteLineItemProductFamList.addAll(qliProdFamSet);
                   quoteLineItemProductFamList.sort();
                   String productFamily = string.join(quoteLineItemProductFamList,', ' );
                   
                   quoteLineItemBUList.addAll(qliBUSet);
                   quoteLineItemBUList.sort();
                   String businessUnit = string.join(quoteLineItemBUList,', ' );
                   
                   if(q.RollupofProductFamilies__c != productFamily &&  q.ProductBusinessUnits__c != businessUnit ){
                       q.RollupofProductFamilies__c = productFamily;
                        q.ProductBusinessUnits__c = businessUnit;
                   quotesToUpdate.add(q);
                   }
                                     
               }
              //End of for loop above
               
               if(!quotesToUpdate.isEmpty()){
                   upsert quotesToUpdate;
               }
           }
         
                       }
  
            }




Test Class 

@isTest(SeeAllData = true)
public class QLITest {
    
          @isTest static void RollUpQLI(){
       List<QuoteLineItem> listQLI = new List<QuoteLineItem>();
       List<Quote> quotesToUpdate = new List<Quote>();
       Set<Id> ParentIds = new Set<Id>();
      
      
       //Insert product
       Product2 p = new Product2(Name = 'Test Name', BusinessUnit__c = 'CDS', ProductFamily__c = 'Communication Director');   
       insert p;
       //Insert pricebook
       Pricebook2 standardPricebook = new Pricebook2(Id = Test.getStandardPricebookId(), IsActive = true);
       update standardPricebook;
      // Id pricebookId = Test.getStandardPricebookId();
       
       PricebookEntry pbe1 = new PricebookEntry(Pricebook2id = standardPricebook.Id, Product2id=p.Id, isActive = true, unitPrice=100);
       insert pbe1;
              
        Opportunity o = new Opportunity(Pricebook2id = Test.getStandardPricebookId(), Name = 'Test Opp1', RollupofProductFamilies__c = 'Test', ProductBusinessUnits__c = 'Bed Stat', StageName ='Test Stage', CloseDate = date.today());
        insert o;  
        Quote q = new Quote(OpportunityId = o.Id, Name = 'Test Quote', Pricebook2Id = standardPricebook.Id);   
        insert q;
              
       QuoteLineItem oli = new QuoteLineItem(PricebookEntryid = pbe1.Id, ProductFamily__c = 'Bed Stat', QuoteId = q.Id, Product2Id = p.Id, Quantity = 1, UnitPrice = 1); 
       insert oli;
        listQLI.add(oli);
        upsert listQLI;
        ParentIds.add(oli.QuoteId);
        Map<Id, Quote> mapQuote = new Map<Id, Quote>([Select Id, BusinessUnit__c, ProductBusinessUnits__c, RollupofProductFamilies__c, (Select Id, QuoteId, Product2Id, LineNumber, ProductFamily__c,  BusinessUnit__c from QuoteLineItems ) From Quote Where Id In: ParentIds]);                                                   

        for(Quote quote: mapQuote.values()){
             List<String> qliProdFamList = new List<String>();
             Set<String> qlitProdFamSet = new Set<String>();
             Set<String> qlitBUset = new Set<String>();
             List<String> qliBUList = new List<String>();
              for(QuoteLineItem ql: quote.QuoteLineItems){
                       
                       qlitProdFamSet.add(ql.ProductFamily__c);
                       qlitBUset.add(ql.BusinessUnit__c);

                   }
                   qliProdFamList.addAll(qlitProdFamSet);
                   qliProdFamList.sort();
                   String productFamily = string.join(qliProdFamList,', ' );
            
                   qliBUList.addAll(qlitBUset);
                   qliBUList.sort();
                   String bizUnit = string.join(qliBUList,', ' );
            if(quote.RollupofProductFamilies__c != productFamily && quote.BusinessUnit__c != bizUnit){
                 quote.RollupofProductFamilies__c = productFamily;
                 quote.ProductBusinessUnits__c = bizUnit;
                   quotesToUpdate.add(quote);
                   }
        }
        upsert quotesToUpdate;
             
        
        test.startTest();
    //    if(quotesToUpdate.size()>0 && listQLI.size()>0){
         
         QuoteRollupPFBU.updateQuote(listQLI);
  //      }
        test.stopTest();
       
    }
    
    


}


Trigger

trigger PrimaryQliTrigger on QuoteLineItem (before insert, before update, after insert, after update, before delete, after delete) {
    
        if(Trigger.isBefore){
        if(Trigger.isInsert){   
        }
        if(Trigger.isUpdate){
                    }
        if(Trigger.isDelete){
                    }
    }
    
 if(Trigger.isAfter){
        if(Trigger.isInsert){ 
             QuoteRollupPFBU.updateQuote(trigger.new);
        }
       if(Trigger.isUpdate || Trigger.isInsert ){
       //    QuoteRollupPFBU.updateQuote(trigger.new);
                    }
        if(Trigger.isDelete){
                    }
    }    


    
    

}

 
  • May 22, 2019
  • Like
  • 0
Hello all, 

I am trying to correct an error in  my test class which states 'System.NullPointerException: Attempt to de-reference a null object'. The two lines where I'm receiving error are in the test class -  AccountActiveProducts.updateAccounts(listAssets); and in the class 
 List<Account> accountsToUpdate = new List<Account>();
Which object isn't being instantiated? Below are the classes. Thank you for your help. 

Test Class 

@isTest 

public class AccountActiveProductsTest {
    
    @isTest static void RollupAsset(){
        List<Asset> listAssets = new List<Asset>();
        Set<String> assetSet = new Set<String>();
        Account aTest = new Account(name='Test Acct', billingcity='test', billingstate='Maryland');
        insert aTest;
        //create asset
        Asset asset = new Asset(name = 'Asset 1', AccountId = aTest.Id, ProductFamily__c = 'Bed Stat', Status = 'Shipped' );
        insert asset;
        List<Account> listAccounts = new List<Account>();
        List<Account> listAccountstoUpdate = new List<Account>();
        
        Integer numAssets;
        for(Integer i=0; i<200; i++){
            Asset ast = new Asset(Name = 'Test Asset' + i, AccountId = aTest.Id, ProductFamily__c = 'Bed Stat', Status = 'Shipped');
               if(ast.Status != 'Retired' || ast.Status != 'Obsolete'){
            assetSet.add(ast.ProductFamily__c);
        }
            listAssets.add(ast);
          
        }
        insert listAssets;
        
        Set<Id> ParentIds = new Set<Id>();
        ParentIds.add(asset.AccountId);
        
        assetSet.add(asset.ProductFamily__c);
        
        listAccounts.add(aTest);
        Map<Id, Account> mapAccount = new Map<Id, Account>([Select Id, ProductsOwned__c, (Select Id, ProductFamily__c, Status from Assets Where  (Status != 'Retired' OR Status != 'Obsolete' OR Status != null)) From Account Where Id In: ParentIds]);  
        List<String> assetList = new List<String>();
        assetList.addAll(assetSet);
        test.startTest();
        AccountActiveProducts aap  = new AccountActiveProducts();
        listAssets.add(asset);
        asset.ProductFamily__c = 'Communication Director';
       String productFamily = string.join(assetList,', ' );
           if(aTest.ProductsOwned__c != productFamily){
                       aTest.ProductsOwned__c = productFamily;
                   listAccountstoUpdate.add(aTest);
                   }
        
          if(!listAccountstoUpdate.isEmpty()){
                   upsert listAccountstoUpdate;
               }
       
        if(listAssets.size() > 0){
             update listAssets;
       AccountActiveProducts.updateAccounts(listAssets);
        }
        upsert listAccounts;
        test.stopTest();
    }

}

Class

public class AccountActiveProducts {
    
        public static void updateAccounts(List<Asset> assetLists){
            Set<String> setAssetsToRemove = new  Set<String>();
            List<String> listAssetsToRemove = new List<String>();
            Set<Id> ParentIds = new Set<Id>();
            for(Asset asset:assetLists){
                ParentIds.add(asset.AccountId); 
            }                                            
            Map<Id, Account> mapAccount = new Map<Id, Account>([Select Id, ProductsOwned__c, (Select Id, ProductFamily__c, Status from Assets Where  (Status != 'Retired' OR Status != 'Obsolete' OR Status != null)) From Account Where Id In: ParentIds]);                                                   

            List<Account> accountsToUpdate = new List<Account>();
   
           
            
           if(Trigger.isInsert || Trigger.isUpdate){ 
               for(Account ac : mapAccount.values()){
  
                   List<String> assetList = new List<String>();
                   Set<String> assetSet = new Set<String>();
                   
                   for(Asset accountAsset: ac.assets){
                       if(accountAsset.Status != 'Retired' || accountAsset.Status != 'Obsolete' ){
                       assetSet.add(accountAsset.ProductFamily__c);
                       }
                       
                       if(accountAsset.Status == 'Retired' || accountAsset.Status == 'Obsolete'){
                          
                          assetSet.remove(accountAsset.ProductFamily__c);
                       }
                       
                   }
                   assetList.addAll(assetSet);
                   assetList.sort();
                   String productFamily = string.join(assetList,', ' );
                   
                   if(ac.ProductsOwned__c != productFamily){
                       ac.ProductsOwned__c = productFamily;
                   accountsToUpdate.add(ac);
                   }
               }
               
              //End of for loop above
              
          
               
               if(!accountsToUpdate.isEmpty()){
                   upsert accountsToUpdate;
               }
           }
            
  
            }

}
  • April 30, 2019
  • Like
  • 0