• Morgan Marchese
  • NEWBIE
  • 120 Points
  • Member since 2015

  • Chatter
    Feed
  • 3
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 34
    Replies
trigger ba on Task (after update, after insert) {
    
    GetMaxActivityDate ad= new GetMaxActivityDate();
    
    
    
    Set<ID> ids = Trigger.newMap.keySet();
    
    List<Task> tk = [select id, whoId,OwnerId from Task where id = :ids limit 1000];
    System.debug('b tasks:'+ tk+ ' size:'+tk.size());
    List<ID> idzz = new List<ID>{};
        
        for(Task a: tk)
    {
        idzz.add(a.whoId);
    }
        
    
    List<Lead> ldz = [select name,id, Sales_Last_Activity_Date__c, Sales_First_Activity_Date__c, OwnerId, IsConverted from Lead where id = :idzz limit 1000];
    
    System.debug('b ids:'+ idzz+'. leads:' + ldz + ' size:' + ldz.size());
    
    List<Lead> updateld = new List<Lead>{};
    
    
    for(Lead a : ldz)
    {
        
        
    
    
    
    
    
                    String ldd = a.id;
        
        if(ldd!=null)
        {
           
        String lds = ldd.subString(0,3);
        
        System.debug('lds: '+ lds);
        
        if(lds.equals('00Q'))
        {
            
             List<aggregateResult> dates = new List <aggregateResult>();
        

        
        
        
       // Lead ld = [select name,id, Sales_Last_Activity_Date__c, Sales_First_Activity_Date__c, IsConverted from Lead where id = :a.WhoId limit 1];
        
        
        
        if(a!=null)
        {
            System.debug('b ' + lds);
            
			Set<ID> taskset = new Set<ID>();
			List<ID>result = new List<ID>();            
            taskset.addAll(idzz);
            result.addAll(taskset);
            System.debug('taskset:'+ taskset.size()+' result:'+result.size());
            
            
            for(ID b:result)
            {
            
            if(b == a.Id)
                {
                     dates = ad.getMaxActivity(b);
                    System.debug('b triggered:  max:'+ (Date)dates[0].get('myMax') + ' min: '+ (Date)dates[0].get('myMin') + 'last activity date:'+ a.Sales_Last_Activity_Date__c + ' first activity date ' +  a.Sales_First_Activity_Date__c+  ' isconverted:'+ a.IsConverted );
                        System.debug('b triggered: lead:'+ a);
                    if(a.IsConverted == false && (dates[0].get('myMax')!=null) && dates[0].get('myMin')!=null && (a.Sales_Last_Activity_Date__c != (Date)dates[0].get('myMax')||a.Sales_First_Activity_Date__c != (Date)dates[0].get('myMin')))
                    {
                        System.debug('Activity_date updated');
                        
                        a.Sales_Last_Activity_Date__c = (Date)dates[0].get('myMax');
                        a.Sales_First_Activity_Date__c = (Date)dates[0].get('myMin');
                        
                        updateld.add(a);
                    }
                    
                    
                }
                
            }
            
        }
        }

        }
    }
    
    update updateld;
    
    
    
    
    
    for(Task a: Trigger.New)
    {

      
        
        
        
    }

}

  public  List<aggregateResult> getMaxActivity(ID who)
    {
        List<aggregateResult> maxDates = [Select Max(Sales_Activity_Date__c) myMax, Min(Sales_Activity_Date__c) myMin from Task 
         where whoid = :who and status = 'Completed'];
            System.debug('Max is:  ' + maxDates[0].get('myMax') + 'min '+maxDates[0].get('myMin'));  
     
        return maxDates;
    }
I was getting this governor limit error in the past, and I rewrote most of the trigger to hopefully fix that, yet I still occasionally see this error. And from personally inserting a bunch of data, i can't seem to reproduce so its having a hard time debug. 

I'm thinking its due to getMaxActivity though because techinically its a select in a for loop? I'm not sure how else logically I can address this though.

thanks!
 
I need help. Not very good at javascript...yet.

I need a button that will reference a URL that is located within the Account record. Sounds simple right? Maybe it is, but it complicates things for me because of the way that it is constructed.

We have two fields on the record: RRID# and RRID URL. The RRID# is a specific number that we need to assign through dataloader (e.g. 12345). The RRID URL is a complex formula field that refers tot eh RRID#:

"https://prod.vendor.com/Report/Index/?rrid="& text(RRID__c) &"&hash=" &
text(CASE(month(today()), 1, 49*1, 2, 48*2, 3, 50*3, 4, 57*4, 5, 50*5, 6, 48*6, 7, 49*7, 8, 53*8, 9, 80*9, 10, 101*10, 11, 110*11, 12, 115*12, 0) + DAY(today()) + mod( RRID__c , DAY(today())))
&"&partnerkey=1234567PenYs"

So basically, the URL would end up looking something like this:

https://prod.vendor.com/Report/Index/?rrid=15&hash=93&partnerkey=1234567PenYs (https://prod.vendor.com/Report/Index/?rrid=15&hash=93&partnerkey=1234567PenYs)

We want users to be able to click a button as opposed to the link in the body of the record. How would I accomplish this?

Thanks in advance for your help!

Shannon
I have a trigger and am trying to write a test class (see below). The trigger is not working...I have asked for help with no resolution. I am asking again for help with the trigger as well as test class (which is not working either). I think my issue is with the Account ID and Opportunity ID part. 

All I am trying to do is have a contract created when a checkbox on the oppty is checked. 

Please see previous post: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BTEhIAO

TRIGGER:

trigger CreateContract on Opportunity (after insert) {
 private List<Contract> ctr = new List<Contract>();
 
  for(Opportunity o : Trigger.new) {
    if(o.Ready_for_Contract__c == true) {
      Contract c = new Contract(Name = o.Name,
                                Status = 'Draft',
                                Total_Contract_Value__c = o.Total_Sales_Price_of_Products__c,
                                StartDate = o.Contract_Start_Date__c,
                                Payment_Status__c = 'Ready to Be Invoiced',
                                AccountId = o.AccountId,
                                Opportunity_Name__c = o.Id);
        ctr.add(c); 
      }
      insert ctr;
     }    
}

TEST Class:

@isTest
private class TestClassCreateContractTrigger 
{
    static testMethod void validateCreateContract() 
    {       
       Contract c = new Contract(
            Name='Test Account',
            Status = 'Activated',
            Total_Contract_Value__c = decimal.valueof('6995'),
            StartDate = System.Today(),
            Payment_Status__c = 'Ready to Be Invoiced',
            AccountId = Opportunity.AccountId,
            Opportunity_Name__c = Opportunity.Id);
       insert c;
       
      }
}

Thanks in advance for your help!!

Shannon
Developer console is Salesforce's way for us to check debug logs, track governor limit issues, run queries, and generally just debug all of our developer stuff.... and yet, it's TERRIBLE.

It freezes constantly, it often says it couldn't finish "long running operations", switching perspectives causes the whole browser to lock up, and then once the perspective finally changes it takes a huge amount of time to go from tab to tab (if you can go at all). Once it freezes/crashes, good luck getting it back up because it takes forever to load (if it even loads at all).

This thing is supposed to be our lifeline, our tool to help figure out what's wrong, and I can't even get it to work. Is there an alternative to this poorly implemented program? I can't stand this anymore, I've been trying to suffer through it for 3-4 years now and enough is enough. Why do more people not complain about this tool, and why has Salesforce not released something better by now?
Hi All,

We want to override the New Case button with a VF Page that does a check if the account is cancelled or not via a picklist called "Billing Status" on the account object.

If Billing Status == 'Cancelled' we want to hit them with an error message that says they can't create a case for this account, but if Billing Status != 'Cancelled' then we want to proceed to the normal case record type selection/creation pages.

We have written the VF page below, and overwritten the standard button functionality, but when we click on the New Case button it asks us to select record type, and when we select it, it just loops back around and asks us to select record type again. When we select record type the second time and press 'continue', it lets us through to the new case page. We're never presented with the error page, even though the account is cancelled... what are we doing wrong?

VF Page:
<apex:page standardController="Account"
action="
  {!
    IF(Account.Billing_Status__c == "Cancelled", 
       URLFOR($Page.CasePageMessenger, Account.Id,[id=Account.Id],FALSE),
       URLFOR($Action.Case.NewCase, Account.Id,[retURL="/001"], TRUE)
    )
  }">
<apex:pageMessage severity="ERROR" 
    strength="3" 
    title="Case Create" 
    summary="This Account is cancelled and can not receive support.">
</apex:pageMessage>
</apex:page>

 
We have a ligthning community created using Community Builder. We are trying to mask the URL (https://unfriendlyUrl.force.com/path) with our own corporate URL (https://commsite.harms123.com). I have been following this salesforce help documentation, as well as various posts on the dev forum and Salesforce Stack Exchange. Here is the official SFDC documentation:
https://help.salesforce.com/HTViewHelpDoc?id=siteforce_domains.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=siteforce_domains.htm&language=en_US)

So far this is what we've done:
  1. We created a CNAME subdomain on our corporate website, lets call it community.corpsite.com.
  2. We pointed that CNAME to community.corpsite.com.OUR-18-DIGIT-ORGID.live.siteforce.com as instructed in the guide
  3. We went to Site Configuration | Domains in Set​up and created community.corpsite.com as a domain.
  4. We went to Site.com Studio, Site Configuration | Domains and made sure that the custom domain (community.corpsite.com) was listed.
  5. We published the site through both Site.com Studio AND Community Builder

When I go to my browser and go to community.corpsite.com, it redirects me to https://unfriendlyUrl.force.com/path, but doesn't mask the URL. This results in our customers having a poor branding experience, since we ask them to go to community.corpsite.com but they are being redirected to the force.com URL.

What am I doing wrong? From what I read online in their documentation, they seem to indicate that this is possible, but I can't get it to work. Is this possible? Where do I start, what is my best place for documentation on this? Could use some help, been struggling with this all day.

Thanks for your time
Hoping someone can help me here, I'm getting a de-reference null object error on some code. This code has been working perfectly up until now so I'm kind of scratching my head on this one, we haven't made any code changes recently to this class. I know that a de-reference means that I am making a call to a null list or variable, and that to combat that you should do checks for .size > 0 before proceeding with any implementation, but, as far as I can tell, we've already done that?

Salesforce reports the error at line 106 which when looking in Salesforce is this line:
 
System.debug('KLE spc per account : '+accToSPCMap.get(account.id).size() + ' for acc: '+account.id);

That line comes directly after a size check:
if(accToSPCMap.size() > 0){

So, I'm making it past the .size() > 0 check, but then still de-referencing on the System.debug line directly below it. I'm having trouble tracking down WHAT the null is at this point. Anybody see anything I missed or have any suggestions on tracking the null better?  

Thanks for your time.
 
public with sharing class SendAlertForRelatedProductPlans
{
    // Make the constructor private since this is a utility class that should not be instantiated
    private SendAlertForRelatedProductPlans() 
    {
    }

    public static void checkNewSubscriptionProductCharges(List<Zuora__SubscriptionProductCharge__c> newSubscriptionProductCharges) 
    {
       // The below code will query for the accounts related to the SPCs that are being inserted
        Set<Id> accountIdSet = new Set<Id>();
        List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>();

        for(Zuora__SubscriptionProductCharge__c spc : newSubscriptionProductCharges)
        {
            if(spc.Zuora__Account__c != null && spc.Zuora__Subscription__c != null) // Make sure the SPCs are related to an account and subscription
            {
                accountIdSet.add(spc.Zuora__Account__c);
            }
        }

        if(accountIdSet.size() == 0)
        {
            System.debug('The SPCs being inserted were not associated with accounts, quitting early.');
            return; // If none of the SPCs are related to accounts, quit early 
        }

        List<Account> accounts = [SELECT Id, Name, Customer_Number__c FROM Account WHERE Id IN :accountIdSet];

        // For each account, we'll need to query for *all* the related active subscriptions.
        Map<Id, Zuora__Subscription__c> subscriptions = new Map<Id, Zuora__Subscription__c>([SELECT Id, Name, Zuora__Account__c
                                                                                             FROM Zuora__Subscription__c 
                                                                                             WHERE Zuora__Account__c IN: accountIdSet 
                                                                                             AND Zuora__Status__c = 'Active'
                                                                                             AND Name != null]);

        // If there are no active subscriptions associated with the accounts specified, we should not continue.
        if(subscriptions.size() == 0)
        {
            System.debug('There were no active subscriptions associated with the SPCs being inserted. Quitting early.');
            return;
        }

        Set<Id> subscriptionIdSet = subscriptions.keySet();

        // We also need to query for all SPCs associated with the above active subscriptions.
        // Retrieve any SPCs that are:
        // (a) Associated with the set of subscriptions ids
        // (b) The subscriptions must be active
        // (c) Associated with the set of account ids within this trigger context 
        // (d) The SPC isn't a Discount Record
        // (e) The SPC has a Rate Plan Classification
        Map<Id,Zuora__SubscriptionProductCharge__c> spcsAssociatedWithActiveSubscription = new Map<Id,Zuora__SubscriptionProductCharge__c>(
                                                                                         [SELECT Id, RatePlanClassification__c, Zuora__Account__c, Zuora__Subscription__c
                                                                                          FROM Zuora__SubscriptionProductCharge__c
                                                                                          WHERE Name != 'Discount' 
                                                                                          AND RatePlanClassification__c != null
                                                                                          AND Zuora__Subscription__c IN : subscriptionIdSet
                                                                                          AND Zuora__Subscription__r.Zuora__Status__c = 'Active' 
                                                                                          AND Zuora__Account__c IN :accountIdSet]);

        Map<Id, List<Zuora__SubscriptionProductCharge__c>> accToSPCMap = new Map<Id, List<Zuora__SubscriptionProductCharge__c>> ();
        for(Zuora__SubscriptionProductCharge__c zs: spcsAssociatedWithActiveSubscription.values()){
            List<Zuora__SubscriptionProductCharge__c> sub = accToSPCMap.get(zs.Zuora__Account__c);
            if(sub == null){
                sub = new List<Zuora__SubscriptionProductCharge__c>();
                sub.add(zs);
                accToSPCMap.put(zs.Zuora__Account__c, sub);
            }else{
                sub.add(zs);
            }

        }

        // The below two maps will capture whether a subscription has:
        // (a) at least one 'Support' related SPC 
        // (b) at least one 'Software' related SPC

        Integer count = 0;

        System.debug('KLE accounts : '+accounts.size());

        for(Account account : accounts){
            Set<ID> subscriptionIdHasSupportSPCs = new Set<ID>();
            Set<ID>  subscriptionIdHasSoftwareSPCs = new Set<ID>();
            Set<ID>  subscriptionIdHasCommSPCs = new Set<ID>();

            if(accToSPCMap.size() > 0){
            System.debug('KLE spc per account : '+accToSPCMap.get(account.id).size() + ' for acc: '+account.id);
                for(Zuora__SubscriptionProductCharge__c spc : accToSPCMap.get(account.id))
                {
                    if(spc.RatePlanClassification__c == 'Support')
                    {
                        subscriptionIdHasSupportSPCs.add(spc.Zuora__Subscription__c);
                        
                    }
                    else if(spc.RatePlanClassification__c == 'Software')
                    {
                        subscriptionIdHasSoftwareSPCs.add(spc.Zuora__Subscription__c);
                        
                    }
                    else if(spc.RatePlanClassification__c == 'Communication')
                    {
                        subscriptionIdHasCommSPCs.add(spc.Zuora__Subscription__c);
                        
                    }
                    count++;

                } // End of loop through SPCs
           }

 
With the introduction of Spring '16 (currently in Preview), the Community Builder for Template based communities like Napili was updated to allow access to the <head> of the page similarly to how you could access scripts in Site.com Studio previously. This allows for the addition of external javascript to the page. I have been having a lot of trouble implementing Salesforce Live Agent into a lightning component so I thought this would be a huge win for me, allowing me to put the javascript in the head where it belonged the whole time, and make sure it always executes.

However, for whatever reason - it seems that the javascript loading in the <head> is unable to find the ElementById in the body? In the below code examples, you will see the head where I drop in Salesforces javascript code for Live Agent buttons, which uses getElementById to display a different element if offline/online. You'll see that I added console.logs to try to find a fault. All 3 console.logs show up in the console, so its definitely reaching them all.

Also, when I manually view the page source of the community page where the lightning component is, and manually try to do a Find for the ElementID, the only reference I find in the source code is my single reference in the <head> - the body doesn't even have any content that resembles the html markup in my lightning component.

Is this issue being caused because...:
  1. The <head>'s inability to see the elements/IDs of elements within lightning components on the page?
  2. The <head> initializes before the lightning component is rendered and so there is no Element by that ID to find at the time of execution?
  3. The ID doesn't show up in the source of the page when manually searching so the <head> probably can't see it either?
  4. Some other reason that I can't think of?
Your time and insight are appreciated!

Live Agent Deployment Javascript in <head>:
<script type='text/javascript' src='https://c.la4-c1cs-was.salesforceliveagent.com/content/g/js/36.0/deployment.js'></script>

<script type='text/javascript'>
    liveagent.init('https://d.la4-c1cs-was.salesforceliveagent.com/chat', '*****Removed*****', '*****Removed*****');
    console.log('MSIMM - Live Agent Initialized');
</script>

<script type="text/javascript">
    if (!window._laq) { 
        window._laq = []; 
        console.log('MSIMM - !window._laq');
    }
    window._laq.push(function(){
        liveagent.showWhenOnline('ABCD1234',     document.getElementById('liveagent_button_online_ABCD1234'));
	    liveagent.showWhenOffline('ABCD1234',     document.getElementById('liveagent_button_offline_ABCD1234'));
        console.log('MSIMM - window._laq.push');
    });
</script>

The ElementIDs above are found in a lightning component on our home page. It is a very simple component that is mostly HTML:
 
<aura:component implements="forceCommunity:availableForAllPageTypes" controller="MSI_PermissionUtil">
    <ltng:require scripts="" styles="/resource/MSIImages5/msiImages.css"/>
    <aura:handler name="init" value="{!this}" action="{!c.init}" />  
    
    <!-- use this to make after render actions -->
    <aura:attribute name="isDoneRenderingLPB" type="Boolean" default="false"/>
    <aura:handler event="aura:doneRendering" action="{!c.onAfterRender}"/>    
    
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-4 col-md-4 msiBoxCol">
                <a href="" id="liveagent_button_online_ABCD1234" class="thumbnail msiBox1" style=" text-align:center;padding-bottom: 2em;" onclick="{!c.startChat}">
                    <div class="msi-img1" style="padding-top:20px;"></div>
                    <h3>Live Chat Online</h3>
                </a>
   
                <a href="" id="liveagent_button_offline_ABCD1234" class="thumbnail msiBox1" style=" text-align:center;padding-bottom: 2em;display: none;">
                    <div class="msi-img1" style="padding-top:20px;"></div>
                    <h3>Live Chat Offline</h3>
                </a>

            </div>
        </div>
    </div>
</aura:component>




 
Hi all - I'm trying to find some resources/help regarding implementation of Salesforce Live Agent into Salesforce Lightning Components. Considering both of these are out-of-the-box Salesforce features I am surprised to find myself having so much difficulty getting these to work. This is also all so new that resources online seem very sparse, almost non-existent. Can anyone suggest any starting point that will help me implement Live Agent deployment/buttons within lightning components? Has anyone achieved this functionality themselves that could provide some pointers?

I found a post on stackExchange where someone commented saying that they've managed to get it working but they didn't clarify exactly how,
http://salesforce.stackexchange.com/questions/94045/winter-16-community-builder-live-agent-and-content-security-policy-issues, and I've already asked them in another comment if they could be more specific but haven't heard back yet.

Thanks!
Hi All - We have a custom object, called "Subscription Product & Charge", and we have a trigger on it that executes many different apex classes, called "SubscriptionProductChargeTrigger". Sometimes bulk inserts by a third party cause CPU limits on some old bulky code, and I usually end up editing the trigger in sandbox, commenting out the line that causes the limit issue, deploying to prod, running the bulk insert, and then editing the trigger again in sandbox to remove the comment and deploy to prod again. This is of course time consuming.

So, just this weekend I added a Custom Setting (List) called "MSI_TriggerControl" and created 7 checkbox fields with the intention of being able to "De-activate" the trigger by setting them to true, without doing what I just did above ^

I added to the trigger to get the instance of 'TriggerControl' from my MSI_TriggerControl Custom Setting under the alias 'settings', and then directly following that I attempt to create and set 7 distinct Boolean values using the respective true/false value of the corresponding checkbox in MSI_TriggerControl__c('TriggerControl'). This works perfectly in dev and properly disables sections of the trigger during all testing, but during deployment it throws a de-reference null exception on line 6 which is the first Boolean I am trying to set (Disable_AlertForRelatedSPC). Yes the 'TriggerControl' record is created and yes I deployed all 7 checkbox fields w/ the same API names to Production already... All I can say is that every time one of my test classes attempts to insert an SPC I get a de-reference on line 6 of this trigger.

I modified the trigger using some help and resources from: http://www.sfdc99.com/2014/03/02/change-your-code-on-the-fly-using-custom-settings/

Here is my new code:
trigger SubscriptionProductChargeTrigger on Zuora__SubscriptionProductCharge__c (after insert, after update)
{

// Grab Custom Setting values
    MSI_TriggerControl__c settings = MSI_TriggerControl__c.getInstance('TriggerControl');
    Boolean Disable_AlertForRelatedSPC = settings.Disable_SPCTrigger_AlertForRelatedSPC__c;
    Boolean Disable_SetAnniversaryDate = settings.Disable_SPCTrigger_SetAnniversaryDate__c;   
    Boolean Disable_UpdateSupportLevel = settings.Disable_SPCTrigger_UpdateSupportLevel__c;   
    Boolean Disable_InsertCasesUsingSPC = settings.Disable_SPCTrigger_InsertCasesUsingSPC__c;  
    Boolean Disable_UpdateTrainingMinutes = settings.Disable_SPCTrigger_UpdateTrainingMinutes__c;    
    Boolean Disable_UpdateAccountRecord = settings.Disable_SPCTrigger_UpdateAccountRecord__c;  
    Boolean Disable_CreateUpdateSPC = settings.Disable_SPCTrigger_CreateUpdateSPC__c;
    
    // ********************
    // *** AFTER INSERT ***
    //*********************

    /*
    if(TriggerControl__c.getValues('runSubscriptionProdChargeTrigger') != null)
        return;
    */
    if(trigger.isAfter && trigger.isInsert){

        //Account update map moved here so Accounts will be updated only once
        Map<ID, Account> accountsMap = new Map<ID, Account>();
        if(Disable_AlertForRelatedSPC == false){
        SendAlertForRelatedProductPlans.checkNewSubscriptionProductCharges(trigger.new); // No objects are modified
        }
        if(Disable_SetAnniversaryDate == false){
        AccountUpdateHandler.updateAnniversaryDateUsingSPCList(trigger.new, accountsMap); // This updates accounts
        }
        if(Disable_UpdateSupportLevel == false){
        AccountUpdateHandler.updateSupportLevelUsingSPCList(trigger.new, accountsMap); // This updates accounts
        }
        if(!ZuoraUtilityClass.isZuoraSyncRunning()){
            // Note: The below two method calls should not be separated.  If we insert cases, we must update accounts as well
            if(Disable_InsertCasesUsingSPC == false){
            CaseHandler.insertCasesUsingSPCList(trigger.new); // This inserts cases 
            }
           // AccountUpdateHandler.updateInstallTypeUsingSPCList(trigger.new, accountsMap); // This updates accounts
        }
        if(Disable_UpdateTrainingMinutes == false){
        AccountUpdateHandler.updateTotalTrainingMinutes(trigger.new, accountsMap); // This updates accounts        
        }
        if(Disable_UpdateAccountRecord == false){
        AccountUpdateFromSPC.updateAccountRecord(trigger.New, accountsMap); //Updates Billing Status, Active and Platform Application fields on the Account
        }
        try{
            //one account update instead of many
            update accountsMap.values();
        }
        catch(DmlException e){
            System.debug('The following exception has occurred: ' + e.getMessage());

        } 

        if(Disable_CreateUpdateSPC == false){
        CRAHandlerUsingSPCClass.CreateUpdateCRARecord(trigger.New); //This creates/updates CRA (Account Administration Record)
        }
    }
}
Help me Salesforce Developer forum, you're my only hope!
 

I'm completely new to SSO, so please bare with me... I am trying to setup Salesforce as the IDP using SAML 2.0 for a third party application called Aha.io. I've followed this guide to Enable Salesforce as an Identity Provider:
https://help.salesforce.com/apex/HTViewHelpDoc?id=identity_provider_enable.htm&language=en (https://help.salesforce.com/apex/HTViewHelpDoc?id=identity_provider_enable.htm&language=en)

After setting up my domain and enabling the required items, I then went to my Identity Provider Setup, and downloaded the Metadata XML file, which I then uploaded into Aha in their SAML 2.0 Configuration Section (they have an option to upload a Metadata file to be read for setup).

Now at this point, when I try to go to our aha.io portal (http://msidev.ideas.aha.io), it attempts to redirect me to Salesforce for my Single Sign-On, but instead of being logged in and redirected back to Aha, I receive the error "Invalid HTTP Method".

At this point, I'm stuck. I can't find any documentation specific to this Single Sign-On error, or any additional setup instructions for setting up SFDC as the IDP. Has anyone encountered this error before? I don't know if there is a problem with my IDP setup, or if there is a problem with Salesforce attempting to redirect me back to the service provider after authentication. The Identity Provider Event Log is blank, so I have no information to go off of.

Can I assume that the metadata that I used to setup SFDC as my IDP is correct and that Aha is correctly bringing me to Salesforce to authenticate? If so, why am I getting this error instead of being passed back to Aha?

I'll take any help I can get, please. Let's solve this together!

 

I have 3 different doFind's on my Pre-Chat form, one to find Accounts by Account Number (Auto Number field), one is to find customers by email field, and one is to find cases by case field.

When I had only one doFind in my prechat form for accounts by account number, it would automatically open up a sub-tab within the Service Console and display the correct account when the customer gave us their number in the form. However, when I introduced my 2 additional doFinds (customers by email and cases by case number), I expected it to give me 3 separate sub-tabs, one for each match. One account subtab, one contact subtab, and one case subtab. Instead, I am just receiving one sub-tab called "Search Results" which displays one account that matched, one contact that matched, and one case that matched:

User-added image

My user has to physically click on each of these 3 search results to open each in its own subtab.

I expected each of my 3 doFinds to open in its own tab since that was the result when my form had only one doFind. They are separate finds for different records so I figured it would work the same way - is this not the case? Is the functionality I am experiencing considered correct, or am I doing something wrong? My ideal solution would be that if the customer fills out all 3 fields, we get 3 subtabs within the Live Agent session in the console, specific to each record that we found that matched.

I hope this makes sense, please let me know if I can clarify any further.

Thanks!
I am working on a PreChat VisualForce page. On that page, the customer enters the following info into the perchat form:
First Name (FirstNameDetail), Last Name(LastNameDetail), Email(EmailDetail), and Customer Number (CustomerNumber).

I am trying to do 2 separate isExactMatch hidden fields:
  1. Open the Account if CustomerNumber in the form is an exact match to Customer_Number__c custom field on Account
  2. Open the Contact if EmailDetail in the form is an exact match to Email on Contact AND the CustomerNumber field in the form is an exact match to the Customer_Number__c field on the Contact.
Note: The Customer_Number__c field on the Contact is a text based Formula field that just displays 'Account.Customer_Number__c' on each Contact Record.

I know that INDIVIDUALLY, each of my ExactMatches work. I know this because I tested the Account ExactMatch by itself by removing the Contact ExactMatch from the page, and I also did the reverse and tested the Contact ExactMatch by removing the Account ExactMatch. In each scenario, the Account or Contact record was successfully opened as an Exact Match in a subtab in the console. However, when adding both together to the page, it doesn't open 2 sub-tabs as I'm hoping it would.

Desired Result:
  1. If Customer Number matches on the Account but Email/Customer Number doesn't match on the contact - I want to load the Account Page only.
  2. If Customer Number matches on Account AND Email/Customer Number on Contact matches, I want to have the Account Page AND the Contact Page loaded as 2 separate sub-tabs within the Service Console window for the live agent session.

Current Result:
Right now with my current implementation, desired result #1 works as expected. I enter a customer number and an incorrect email, and it loads up the correct account and no contact record.
However, desired result #2 is not working as expected. If I enter a customer number and a CORRECT email of a contact linked to that account, it loads up a Search Results page that displays the Account and the Contact, rather than loading the account and contact into their own subtabs, as seen in the screenshot below:
User-added image
My desired result is that when it exact matches all criteria, it opens up the Account in a Subtab, and the Contact in another subtab, instead of just giving me a search results page like I'm getting now.

Reason:
The reason I am doing this is because in our specific Salesforce Instance, it is possible for a contact to exist more than once with the same email address, but under different accounts, because one contact may own or operate multiple accounts. Each of our accounts is identified by a unique number called Customer Number, and so I need to match for contacts of THAT specific account, rather than just contacts as a whole. If I limit myself to searching only Email, I could end up with 20+ different contact results of the same person on 20+ different accounts.

Code:
<apex:page showHeader="false"> 
<!-- CSS and SCRIPTS removed to save space on Dev Forum Post-->
<div>
    <form method='post' id='prechatForm'> 
        <table class="formTable">
            <tr>
                <td><b>First Name:</b></td>
                <td><input type='text' name='liveagent.prechat:FirstNameDetail' /> </td>
            </tr>
            <tr>
                <td><b>Last Name:</b></td>
                <td><input type='text' name='liveagent.prechat:LastNameDetail' /></td>
            </tr>
            <tr>
                <td><b>Email Address:</b></td>
                <td><input type='text' name='liveagent.prechat:EmailDetail' /></td>
            </tr>
            <tr>
                <td><b>Customer Number:</b></td>
                <td><input type='text' name='liveagent.prechat:CustomerNumber' /></td>
            </tr>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td><b>Department:</b></td>
                <td>
                        <select name="liveagent.prechat.buttons">
                        <!-- Values are LiveChatButton IDs. -->
                        <option value="573U0000000TTKV">ABC Support</option>
                        <option value="573U0000000TTzY">XYZ Support</option>
                        <!--<option value="573U0000000TTzY,573U0000000TTKV">XYZ Support If Available,
                        otherwise ABC Support</option>-->
                        </select>
                </td>
            </tr>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td><input type='submit' value='Start Chat' id='prechat_submit'/></td>
            </tr>
        </table>

<!--Save Email Address to Chat Transcript-->
<input type="hidden" name="liveagent.prechat.save:EmailDetail" value="Email__c" />
<!--Save Customer Number to Chat Transcript-->
<input type="hidden" name="liveagent.prechat.save:CustomerNumber" value="Customer_Number__c" />

<!--POP OUTS-->

    <!-- ACCOUNT -->
        <!--Map To an Account if CustomerNumber variable in form equals Customer_Number__c custom field on account -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map:Account"
        value="Customer_Number__c,CustomerNumber" />
        
        <!--doFind where Customer_Number__c match = true -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Account"
        value="Customer_Number__c,true" />
        
        <!--Open the Account when we find an Exact Match -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Account"
        value="Customer_Number__c,true" />

    <!-- CONTACT -->
        <!--Map to a Contact if CustomerNumber variable and EmailDetail variable in form match to Customer_Number__c and Email field on contact-->
        <input type="hidden" name="liveagent.prechat.findorcreate.map:Contact"
        value="Customer_Number__c,CustomerNumber;Email,EmailDetail" />
        
        <!--doFind where Customer_Number__c match = true and Email match = true -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Contact"
        value="Customer_Number__c,true;Email,true" />
        
        <!--Open the Contact whne we find an Exact Match-->
        <input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Contact"
        value="Customer_Number__c,true;Email,true" />

</form> 
</div>
</apex:page>


I've been racking my brain on this all morning and not getting any farther - could use some extra brain power from the community. All thoughts and input appreciated. Thanks!
Hi everyone - I am new to setting up an IDP but now have a requirement for it and am trying to figure out how (if at all) I can get Salesforce to work for me and my customers.

We are currently in the process of launching our first Salesforce Community using the Napili template. We have been looking at a Product Management app called Aha (www.aha.io) which offers an Idea Portal that is nearly identical in function to Salesforce Ideas, but with a much more robust integration and interface to help our product team deliver on popular ideas. BUT, Out-of-the-box, has its own login system.

They have documentation on their website about both JWT and SAML 2.0 SSO options, but their documentation isn't specific to Salesforce Communities (or Salesforce at all for that matter). Since this is still a bit foreign to me, I am not sure what I can do or can't do to accomplish this within SF. Our goal is to have our customers login to our Salesforce Community using their SFDC Community Username/Password, and then, using SFDC as the Identity Provider, have them logged in immediately using those credentials when clicking the Aha Idea Portal link.

I was hoping someone could take a look at the 2 online resources that Aha provides, one for JWT and one for SAML, and tell me if I can make either of them work to accomplish our goal. If someone could help point me in the right direction that would be great.

JWT: http://support.aha.io/hc/en-us/articles/203636345-Using-JSON-Web-Token-JWT-for-Idea-Portal-single-sign-on-SSO-
SAML 2.0: http://support.aha.io/hc/en-us/articles/205694305-Configure-SAML-2-0-Single-Sign-On-for-Ideas-portal


Can I accomplish my goal of making SFDC an Identity Provider that will allow my customers to log in to Aha! Ideas using their SF Community credentials?
I made some major changes to a handler class that references custom objects from a managed package and it no longer passes 75% coverage so I needed to add a lot of test coverage to handle it. In my test coverage I created a new account, new opportunity linked to that account, new zuora quote (managed package) linked to the opp and account, and new quote charges (managed package) linked to the zuora quote.

However, the test class fails with an error on attempting to de-refernce a null object on the line that is supposed to insert the quote charges (last object). Coincidentally, that is the object that I need to insert to increase coverage. While investigating, I went into SFDC and manually created a quote charge and saved it. After I press save, it immediately tries to load the newly saved record but instead brings me to the page that says:

"The record you attempted to access has been deleted. The user who deleted this record may be able to recover it from the Recycle Bin. Deleted data is stored in the Recycle Bin for 15 days."

What is the easiest/best way for me to determine how/why these records are being deleted immediately after creation?
Hi all, I'm new to apex but currently going through some online courses but haven't quite grasped how I can achieve this yet...

Scenario: We have a custom object from our Zuora managed package called 'Quote Charge'. Within this object are many records. Two of these records are technically 'associated' with each other, but not using a lookup field or any traditional SFDC linking. Instead, they have a custom field that shares a unique value between these 2 'associated' records. So, both of these records have a field where the value is "20150814ABCD" for example - that field is unique to these TWO records and will never be found on any other records of this object. One of these 2 records is named "Discount", and the other one can have any varying name.

Goal: I need to, using apex I presume, find these 2 matching records based on that custom field being an exact match between the 2, and then take the discount % from a field on the record named "Discount" and apply it to another custom field on the record that isn't named "Discount"

Can anyone give me a good starting point for this/point me in the right direction? I started writing some code in a class to play around with the idea, but I don't think I'm going about it the best way. Would appreciate some feedback from the SFDC Gurus.

Many thanks,

Morgan
Hi all,

Here is some very basic before insert code I am using in an account trigger - my intent is to copy the OwnerId (or OwnerName) to a text field called Original_Account_Owner__c. This field would retain a historical record of who the original account owner was so that we can always report on that data even if the current owner is changed.
 
if (Trigger.isBefore && Trigger.isInsert) {
        for(Account acct : Trigger.new){
            // Check that the owner is a user (not a queue)
            if( ((String)acct.OwnerId).substring(0,3) == '005' && acct.Original_Account_Owner__c == null ){
            acct.Original_Account_Owner__c = acct.OwnerId;
            }
            else{
            // In case of Queue (which shouldn't happen), System Debug.
            System.debug('found a queue when we shouldn't have...' + acct.OwnerId);
            }
        }

This works perfectly if I convert a lead for myself, with myself set as the Record Owner during the conversion process...

However:
If I have two employees (Emp A and Emp B) and Emp A is converting a lead but during the conversion process he/she sets the Record Owner to Emp B, the end result after my trigger runs is that the "Original Account Owner" is showing Emp A and the "Account Owner" is showing Emp B when in reality I want the "Original Account Owner" and the "Account Owner" to BOTH be Emp B because that was the Record Owner selected during the conversion.

My assumption was that if the record owner is selected during conversion, it would be the one that the new account record is created with - so my trigger should just pick up the Account Owner prior to insert and set it on my custom field... instead, it looks like it assumes that I am the Record Owner during insert and then quickly changes it afterwards?

Is there any way I can combat this and get the end result I am looking for, or am I stuck because of the nature of the account creation/reassignment process during conversion?

Many thanks for your input everyone!
We created our first outbound message WFR in our Production environment to send some account information to an external source URL whenever a custom object (Account Administration) is created or edited. I know that the workflow rule is firing, because I checked the developer console log AND I also added an email alert to the WFR to email myself when it triggers to verify, and I received the email every time.

However, no outbound message appears to be sent, even though one is setup, tied to an active WFR, and is being sent by an Active User with the System Administrator profile which I have confirmed also has the "Send Outbound Messages" flag set to TRUE in System Permissions.

As I have checked the entire process and everything seems to be correct, I am at a loss. I saw posts from other SFDC users that indicated that their issue ended up being that the profile didn't have the "Send Outbound Messages" permission, but I've confirmed that the "User to Send As" has system admin profile and definitely has that option enabled. I've even tried changing this to another user, including my own user and 2 different API users, to no avail.

Here is my WFR:

User-added image

Here is the Outbound Message:
User-added image

And Here is the User Setup/Profile of the Pipeline API User:

User-added image

Here is the Log out of the Developer Console showing the WFR Triggering and indicating 1 Outbound Message:

User-added image

I'm really at a loss here... the flow triggers, the outbound message is setup, and the user has access - but nothing shows up in my Outbound queue, not even any errors, and our developers report no attempts to ping their web service.

I opened a ticket with Salesforce support and was told that they would call me the next day to discuss it. When they finally did call me, all they did was tell me that I had to come here since it was outside of their scope of support. So here I am, grasping at straws, hoping someone can tell me what we've done wrong here or where to go next.

All of your input is appreciated!
We created our first outbound message WFR in our Production environment to send some account information to an external source URL whenever a custom object (Account Administration) is created or edited. I know that the workflow rule is firing, because I checked the developer console log AND I also added an email alert to the WFR to email myself when it triggers to verify, and I received the email every time.

However, no outbound message appears to be sent, even though one is setup, tied to an active WFR, and is being sent by an Active User with the System Administrator profile which I have confirmed also has the "Send Outbound Messages" flag set to TRUE in System Permissions.

As I have checked the entire process and everything seems to be correct, I am at a loss. I saw posts from other SFDC users that indicated that their issue ended up being that the profile didn't have the "Send Outbound Messages" permission, but I've confirmed that the "User to Send As" has system admin profile and definitely has that option enabled. I've even tried changing this to another user, including my own user and 2 different API users, to no avail.

Here is my WFR:

User-added image

Here is the Outbound Message:
User-added image

And Here is the User Setup/Profile of the Pipeline API User:

User-added image

Here is the Log out of the Developer Console showing the WFR Triggering and indicating 1 Outbound Message:

User-added image

I'm really at a loss here... the flow triggers, the outbound message is setup, and the user has access - but nothing shows up in my Outbound queue, not even any errors, and our developers report no attempts to ping their web service.

I opened a ticket with Salesforce support and was told that they would call me the next day to discuss it. When they finally did call me, all they did was tell me that I had to come here since it was outside of their scope of support. So here I am, grasping at straws, hoping someone can tell me what we've done wrong here or where to go next.

All of your input is appreciated!
Developer console is Salesforce's way for us to check debug logs, track governor limit issues, run queries, and generally just debug all of our developer stuff.... and yet, it's TERRIBLE.

It freezes constantly, it often says it couldn't finish "long running operations", switching perspectives causes the whole browser to lock up, and then once the perspective finally changes it takes a huge amount of time to go from tab to tab (if you can go at all). Once it freezes/crashes, good luck getting it back up because it takes forever to load (if it even loads at all).

This thing is supposed to be our lifeline, our tool to help figure out what's wrong, and I can't even get it to work. Is there an alternative to this poorly implemented program? I can't stand this anymore, I've been trying to suffer through it for 3-4 years now and enough is enough. Why do more people not complain about this tool, and why has Salesforce not released something better by now?
trigger ba on Task (after update, after insert) {
    
    GetMaxActivityDate ad= new GetMaxActivityDate();
    
    
    
    Set<ID> ids = Trigger.newMap.keySet();
    
    List<Task> tk = [select id, whoId,OwnerId from Task where id = :ids limit 1000];
    System.debug('b tasks:'+ tk+ ' size:'+tk.size());
    List<ID> idzz = new List<ID>{};
        
        for(Task a: tk)
    {
        idzz.add(a.whoId);
    }
        
    
    List<Lead> ldz = [select name,id, Sales_Last_Activity_Date__c, Sales_First_Activity_Date__c, OwnerId, IsConverted from Lead where id = :idzz limit 1000];
    
    System.debug('b ids:'+ idzz+'. leads:' + ldz + ' size:' + ldz.size());
    
    List<Lead> updateld = new List<Lead>{};
    
    
    for(Lead a : ldz)
    {
        
        
    
    
    
    
    
                    String ldd = a.id;
        
        if(ldd!=null)
        {
           
        String lds = ldd.subString(0,3);
        
        System.debug('lds: '+ lds);
        
        if(lds.equals('00Q'))
        {
            
             List<aggregateResult> dates = new List <aggregateResult>();
        

        
        
        
       // Lead ld = [select name,id, Sales_Last_Activity_Date__c, Sales_First_Activity_Date__c, IsConverted from Lead where id = :a.WhoId limit 1];
        
        
        
        if(a!=null)
        {
            System.debug('b ' + lds);
            
			Set<ID> taskset = new Set<ID>();
			List<ID>result = new List<ID>();            
            taskset.addAll(idzz);
            result.addAll(taskset);
            System.debug('taskset:'+ taskset.size()+' result:'+result.size());
            
            
            for(ID b:result)
            {
            
            if(b == a.Id)
                {
                     dates = ad.getMaxActivity(b);
                    System.debug('b triggered:  max:'+ (Date)dates[0].get('myMax') + ' min: '+ (Date)dates[0].get('myMin') + 'last activity date:'+ a.Sales_Last_Activity_Date__c + ' first activity date ' +  a.Sales_First_Activity_Date__c+  ' isconverted:'+ a.IsConverted );
                        System.debug('b triggered: lead:'+ a);
                    if(a.IsConverted == false && (dates[0].get('myMax')!=null) && dates[0].get('myMin')!=null && (a.Sales_Last_Activity_Date__c != (Date)dates[0].get('myMax')||a.Sales_First_Activity_Date__c != (Date)dates[0].get('myMin')))
                    {
                        System.debug('Activity_date updated');
                        
                        a.Sales_Last_Activity_Date__c = (Date)dates[0].get('myMax');
                        a.Sales_First_Activity_Date__c = (Date)dates[0].get('myMin');
                        
                        updateld.add(a);
                    }
                    
                    
                }
                
            }
            
        }
        }

        }
    }
    
    update updateld;
    
    
    
    
    
    for(Task a: Trigger.New)
    {

      
        
        
        
    }

}

  public  List<aggregateResult> getMaxActivity(ID who)
    {
        List<aggregateResult> maxDates = [Select Max(Sales_Activity_Date__c) myMax, Min(Sales_Activity_Date__c) myMin from Task 
         where whoid = :who and status = 'Completed'];
            System.debug('Max is:  ' + maxDates[0].get('myMax') + 'min '+maxDates[0].get('myMin'));  
     
        return maxDates;
    }
I was getting this governor limit error in the past, and I rewrote most of the trigger to hopefully fix that, yet I still occasionally see this error. And from personally inserting a bunch of data, i can't seem to reproduce so its having a hard time debug. 

I'm thinking its due to getMaxActivity though because techinically its a select in a for loop? I'm not sure how else logically I can address this though.

thanks!
 
Hey everyone,

I have a VisualForce page embedded within our standard Opportunity layout. Up until now this VF page has just been a table with custom checkbox fields using "inputCheckbox". When a user went to an Opportunity the page would open as normal at the top of the Opportunity page.

However, I've since added an "inputField" to the VF page, which allows the user to fill in one of our existing Lookup fields. The problem is that whenever the user goes to an Opportunity now, the Opportunity will open and then the user is directed down to the VF page instead of staying at the top of the Opportunity.

Is there a reason why the "inputField" parameter causes the screen to immediately redirect down to the VF page?

Thanks,
Greg
We have a ligthning community created using Community Builder. We are trying to mask the URL (https://unfriendlyUrl.force.com/path) with our own corporate URL (https://commsite.harms123.com). I have been following this salesforce help documentation, as well as various posts on the dev forum and Salesforce Stack Exchange. Here is the official SFDC documentation:
https://help.salesforce.com/HTViewHelpDoc?id=siteforce_domains.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=siteforce_domains.htm&language=en_US)

So far this is what we've done:
  1. We created a CNAME subdomain on our corporate website, lets call it community.corpsite.com.
  2. We pointed that CNAME to community.corpsite.com.OUR-18-DIGIT-ORGID.live.siteforce.com as instructed in the guide
  3. We went to Site Configuration | Domains in Set​up and created community.corpsite.com as a domain.
  4. We went to Site.com Studio, Site Configuration | Domains and made sure that the custom domain (community.corpsite.com) was listed.
  5. We published the site through both Site.com Studio AND Community Builder

When I go to my browser and go to community.corpsite.com, it redirects me to https://unfriendlyUrl.force.com/path, but doesn't mask the URL. This results in our customers having a poor branding experience, since we ask them to go to community.corpsite.com but they are being redirected to the force.com URL.

What am I doing wrong? From what I read online in their documentation, they seem to indicate that this is possible, but I can't get it to work. Is this possible? Where do I start, what is my best place for documentation on this? Could use some help, been struggling with this all day.

Thanks for your time
Hoping someone can help me here, I'm getting a de-reference null object error on some code. This code has been working perfectly up until now so I'm kind of scratching my head on this one, we haven't made any code changes recently to this class. I know that a de-reference means that I am making a call to a null list or variable, and that to combat that you should do checks for .size > 0 before proceeding with any implementation, but, as far as I can tell, we've already done that?

Salesforce reports the error at line 106 which when looking in Salesforce is this line:
 
System.debug('KLE spc per account : '+accToSPCMap.get(account.id).size() + ' for acc: '+account.id);

That line comes directly after a size check:
if(accToSPCMap.size() > 0){

So, I'm making it past the .size() > 0 check, but then still de-referencing on the System.debug line directly below it. I'm having trouble tracking down WHAT the null is at this point. Anybody see anything I missed or have any suggestions on tracking the null better?  

Thanks for your time.
 
public with sharing class SendAlertForRelatedProductPlans
{
    // Make the constructor private since this is a utility class that should not be instantiated
    private SendAlertForRelatedProductPlans() 
    {
    }

    public static void checkNewSubscriptionProductCharges(List<Zuora__SubscriptionProductCharge__c> newSubscriptionProductCharges) 
    {
       // The below code will query for the accounts related to the SPCs that are being inserted
        Set<Id> accountIdSet = new Set<Id>();
        List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>();

        for(Zuora__SubscriptionProductCharge__c spc : newSubscriptionProductCharges)
        {
            if(spc.Zuora__Account__c != null && spc.Zuora__Subscription__c != null) // Make sure the SPCs are related to an account and subscription
            {
                accountIdSet.add(spc.Zuora__Account__c);
            }
        }

        if(accountIdSet.size() == 0)
        {
            System.debug('The SPCs being inserted were not associated with accounts, quitting early.');
            return; // If none of the SPCs are related to accounts, quit early 
        }

        List<Account> accounts = [SELECT Id, Name, Customer_Number__c FROM Account WHERE Id IN :accountIdSet];

        // For each account, we'll need to query for *all* the related active subscriptions.
        Map<Id, Zuora__Subscription__c> subscriptions = new Map<Id, Zuora__Subscription__c>([SELECT Id, Name, Zuora__Account__c
                                                                                             FROM Zuora__Subscription__c 
                                                                                             WHERE Zuora__Account__c IN: accountIdSet 
                                                                                             AND Zuora__Status__c = 'Active'
                                                                                             AND Name != null]);

        // If there are no active subscriptions associated with the accounts specified, we should not continue.
        if(subscriptions.size() == 0)
        {
            System.debug('There were no active subscriptions associated with the SPCs being inserted. Quitting early.');
            return;
        }

        Set<Id> subscriptionIdSet = subscriptions.keySet();

        // We also need to query for all SPCs associated with the above active subscriptions.
        // Retrieve any SPCs that are:
        // (a) Associated with the set of subscriptions ids
        // (b) The subscriptions must be active
        // (c) Associated with the set of account ids within this trigger context 
        // (d) The SPC isn't a Discount Record
        // (e) The SPC has a Rate Plan Classification
        Map<Id,Zuora__SubscriptionProductCharge__c> spcsAssociatedWithActiveSubscription = new Map<Id,Zuora__SubscriptionProductCharge__c>(
                                                                                         [SELECT Id, RatePlanClassification__c, Zuora__Account__c, Zuora__Subscription__c
                                                                                          FROM Zuora__SubscriptionProductCharge__c
                                                                                          WHERE Name != 'Discount' 
                                                                                          AND RatePlanClassification__c != null
                                                                                          AND Zuora__Subscription__c IN : subscriptionIdSet
                                                                                          AND Zuora__Subscription__r.Zuora__Status__c = 'Active' 
                                                                                          AND Zuora__Account__c IN :accountIdSet]);

        Map<Id, List<Zuora__SubscriptionProductCharge__c>> accToSPCMap = new Map<Id, List<Zuora__SubscriptionProductCharge__c>> ();
        for(Zuora__SubscriptionProductCharge__c zs: spcsAssociatedWithActiveSubscription.values()){
            List<Zuora__SubscriptionProductCharge__c> sub = accToSPCMap.get(zs.Zuora__Account__c);
            if(sub == null){
                sub = new List<Zuora__SubscriptionProductCharge__c>();
                sub.add(zs);
                accToSPCMap.put(zs.Zuora__Account__c, sub);
            }else{
                sub.add(zs);
            }

        }

        // The below two maps will capture whether a subscription has:
        // (a) at least one 'Support' related SPC 
        // (b) at least one 'Software' related SPC

        Integer count = 0;

        System.debug('KLE accounts : '+accounts.size());

        for(Account account : accounts){
            Set<ID> subscriptionIdHasSupportSPCs = new Set<ID>();
            Set<ID>  subscriptionIdHasSoftwareSPCs = new Set<ID>();
            Set<ID>  subscriptionIdHasCommSPCs = new Set<ID>();

            if(accToSPCMap.size() > 0){
            System.debug('KLE spc per account : '+accToSPCMap.get(account.id).size() + ' for acc: '+account.id);
                for(Zuora__SubscriptionProductCharge__c spc : accToSPCMap.get(account.id))
                {
                    if(spc.RatePlanClassification__c == 'Support')
                    {
                        subscriptionIdHasSupportSPCs.add(spc.Zuora__Subscription__c);
                        
                    }
                    else if(spc.RatePlanClassification__c == 'Software')
                    {
                        subscriptionIdHasSoftwareSPCs.add(spc.Zuora__Subscription__c);
                        
                    }
                    else if(spc.RatePlanClassification__c == 'Communication')
                    {
                        subscriptionIdHasCommSPCs.add(spc.Zuora__Subscription__c);
                        
                    }
                    count++;

                } // End of loop through SPCs
           }

 
I need help. Not very good at javascript...yet.

I need a button that will reference a URL that is located within the Account record. Sounds simple right? Maybe it is, but it complicates things for me because of the way that it is constructed.

We have two fields on the record: RRID# and RRID URL. The RRID# is a specific number that we need to assign through dataloader (e.g. 12345). The RRID URL is a complex formula field that refers tot eh RRID#:

"https://prod.vendor.com/Report/Index/?rrid="& text(RRID__c) &"&hash=" &
text(CASE(month(today()), 1, 49*1, 2, 48*2, 3, 50*3, 4, 57*4, 5, 50*5, 6, 48*6, 7, 49*7, 8, 53*8, 9, 80*9, 10, 101*10, 11, 110*11, 12, 115*12, 0) + DAY(today()) + mod( RRID__c , DAY(today())))
&"&partnerkey=1234567PenYs"

So basically, the URL would end up looking something like this:

https://prod.vendor.com/Report/Index/?rrid=15&hash=93&partnerkey=1234567PenYs (https://prod.vendor.com/Report/Index/?rrid=15&hash=93&partnerkey=1234567PenYs)

We want users to be able to click a button as opposed to the link in the body of the record. How would I accomplish this?

Thanks in advance for your help!

Shannon
How can I modify this code to prohibit custom button from functioning while record is within the approval process? See image for code detail. Also fire alert "Cannot use button while record is within the approval process"

thank you-

User-added image
I have created the code via the Chat Button design, but am unable to add it to the current Communities page. Community Builder does not allow anything be added in, and Site.com does not allow the template to be edited (as it mentions the page is a Lightning template.) Lightning Components can be built, but do not allow for this sort of scripting. How does something scripted get added via Community Builder or Site.com Studio?
Hi All - We have a custom object, called "Subscription Product & Charge", and we have a trigger on it that executes many different apex classes, called "SubscriptionProductChargeTrigger". Sometimes bulk inserts by a third party cause CPU limits on some old bulky code, and I usually end up editing the trigger in sandbox, commenting out the line that causes the limit issue, deploying to prod, running the bulk insert, and then editing the trigger again in sandbox to remove the comment and deploy to prod again. This is of course time consuming.

So, just this weekend I added a Custom Setting (List) called "MSI_TriggerControl" and created 7 checkbox fields with the intention of being able to "De-activate" the trigger by setting them to true, without doing what I just did above ^

I added to the trigger to get the instance of 'TriggerControl' from my MSI_TriggerControl Custom Setting under the alias 'settings', and then directly following that I attempt to create and set 7 distinct Boolean values using the respective true/false value of the corresponding checkbox in MSI_TriggerControl__c('TriggerControl'). This works perfectly in dev and properly disables sections of the trigger during all testing, but during deployment it throws a de-reference null exception on line 6 which is the first Boolean I am trying to set (Disable_AlertForRelatedSPC). Yes the 'TriggerControl' record is created and yes I deployed all 7 checkbox fields w/ the same API names to Production already... All I can say is that every time one of my test classes attempts to insert an SPC I get a de-reference on line 6 of this trigger.

I modified the trigger using some help and resources from: http://www.sfdc99.com/2014/03/02/change-your-code-on-the-fly-using-custom-settings/

Here is my new code:
trigger SubscriptionProductChargeTrigger on Zuora__SubscriptionProductCharge__c (after insert, after update)
{

// Grab Custom Setting values
    MSI_TriggerControl__c settings = MSI_TriggerControl__c.getInstance('TriggerControl');
    Boolean Disable_AlertForRelatedSPC = settings.Disable_SPCTrigger_AlertForRelatedSPC__c;
    Boolean Disable_SetAnniversaryDate = settings.Disable_SPCTrigger_SetAnniversaryDate__c;   
    Boolean Disable_UpdateSupportLevel = settings.Disable_SPCTrigger_UpdateSupportLevel__c;   
    Boolean Disable_InsertCasesUsingSPC = settings.Disable_SPCTrigger_InsertCasesUsingSPC__c;  
    Boolean Disable_UpdateTrainingMinutes = settings.Disable_SPCTrigger_UpdateTrainingMinutes__c;    
    Boolean Disable_UpdateAccountRecord = settings.Disable_SPCTrigger_UpdateAccountRecord__c;  
    Boolean Disable_CreateUpdateSPC = settings.Disable_SPCTrigger_CreateUpdateSPC__c;
    
    // ********************
    // *** AFTER INSERT ***
    //*********************

    /*
    if(TriggerControl__c.getValues('runSubscriptionProdChargeTrigger') != null)
        return;
    */
    if(trigger.isAfter && trigger.isInsert){

        //Account update map moved here so Accounts will be updated only once
        Map<ID, Account> accountsMap = new Map<ID, Account>();
        if(Disable_AlertForRelatedSPC == false){
        SendAlertForRelatedProductPlans.checkNewSubscriptionProductCharges(trigger.new); // No objects are modified
        }
        if(Disable_SetAnniversaryDate == false){
        AccountUpdateHandler.updateAnniversaryDateUsingSPCList(trigger.new, accountsMap); // This updates accounts
        }
        if(Disable_UpdateSupportLevel == false){
        AccountUpdateHandler.updateSupportLevelUsingSPCList(trigger.new, accountsMap); // This updates accounts
        }
        if(!ZuoraUtilityClass.isZuoraSyncRunning()){
            // Note: The below two method calls should not be separated.  If we insert cases, we must update accounts as well
            if(Disable_InsertCasesUsingSPC == false){
            CaseHandler.insertCasesUsingSPCList(trigger.new); // This inserts cases 
            }
           // AccountUpdateHandler.updateInstallTypeUsingSPCList(trigger.new, accountsMap); // This updates accounts
        }
        if(Disable_UpdateTrainingMinutes == false){
        AccountUpdateHandler.updateTotalTrainingMinutes(trigger.new, accountsMap); // This updates accounts        
        }
        if(Disable_UpdateAccountRecord == false){
        AccountUpdateFromSPC.updateAccountRecord(trigger.New, accountsMap); //Updates Billing Status, Active and Platform Application fields on the Account
        }
        try{
            //one account update instead of many
            update accountsMap.values();
        }
        catch(DmlException e){
            System.debug('The following exception has occurred: ' + e.getMessage());

        } 

        if(Disable_CreateUpdateSPC == false){
        CRAHandlerUsingSPCClass.CreateUpdateCRARecord(trigger.New); //This creates/updates CRA (Account Administration Record)
        }
    }
}
Help me Salesforce Developer forum, you're my only hope!
 
I have 3 different doFind's on my Pre-Chat form, one to find Accounts by Account Number (Auto Number field), one is to find customers by email field, and one is to find cases by case field.

When I had only one doFind in my prechat form for accounts by account number, it would automatically open up a sub-tab within the Service Console and display the correct account when the customer gave us their number in the form. However, when I introduced my 2 additional doFinds (customers by email and cases by case number), I expected it to give me 3 separate sub-tabs, one for each match. One account subtab, one contact subtab, and one case subtab. Instead, I am just receiving one sub-tab called "Search Results" which displays one account that matched, one contact that matched, and one case that matched:

User-added image

My user has to physically click on each of these 3 search results to open each in its own subtab.

I expected each of my 3 doFinds to open in its own tab since that was the result when my form had only one doFind. They are separate finds for different records so I figured it would work the same way - is this not the case? Is the functionality I am experiencing considered correct, or am I doing something wrong? My ideal solution would be that if the customer fills out all 3 fields, we get 3 subtabs within the Live Agent session in the console, specific to each record that we found that matched.

I hope this makes sense, please let me know if I can clarify any further.

Thanks!
I am working on a PreChat VisualForce page. On that page, the customer enters the following info into the perchat form:
First Name (FirstNameDetail), Last Name(LastNameDetail), Email(EmailDetail), and Customer Number (CustomerNumber).

I am trying to do 2 separate isExactMatch hidden fields:
  1. Open the Account if CustomerNumber in the form is an exact match to Customer_Number__c custom field on Account
  2. Open the Contact if EmailDetail in the form is an exact match to Email on Contact AND the CustomerNumber field in the form is an exact match to the Customer_Number__c field on the Contact.
Note: The Customer_Number__c field on the Contact is a text based Formula field that just displays 'Account.Customer_Number__c' on each Contact Record.

I know that INDIVIDUALLY, each of my ExactMatches work. I know this because I tested the Account ExactMatch by itself by removing the Contact ExactMatch from the page, and I also did the reverse and tested the Contact ExactMatch by removing the Account ExactMatch. In each scenario, the Account or Contact record was successfully opened as an Exact Match in a subtab in the console. However, when adding both together to the page, it doesn't open 2 sub-tabs as I'm hoping it would.

Desired Result:
  1. If Customer Number matches on the Account but Email/Customer Number doesn't match on the contact - I want to load the Account Page only.
  2. If Customer Number matches on Account AND Email/Customer Number on Contact matches, I want to have the Account Page AND the Contact Page loaded as 2 separate sub-tabs within the Service Console window for the live agent session.

Current Result:
Right now with my current implementation, desired result #1 works as expected. I enter a customer number and an incorrect email, and it loads up the correct account and no contact record.
However, desired result #2 is not working as expected. If I enter a customer number and a CORRECT email of a contact linked to that account, it loads up a Search Results page that displays the Account and the Contact, rather than loading the account and contact into their own subtabs, as seen in the screenshot below:
User-added image
My desired result is that when it exact matches all criteria, it opens up the Account in a Subtab, and the Contact in another subtab, instead of just giving me a search results page like I'm getting now.

Reason:
The reason I am doing this is because in our specific Salesforce Instance, it is possible for a contact to exist more than once with the same email address, but under different accounts, because one contact may own or operate multiple accounts. Each of our accounts is identified by a unique number called Customer Number, and so I need to match for contacts of THAT specific account, rather than just contacts as a whole. If I limit myself to searching only Email, I could end up with 20+ different contact results of the same person on 20+ different accounts.

Code:
<apex:page showHeader="false"> 
<!-- CSS and SCRIPTS removed to save space on Dev Forum Post-->
<div>
    <form method='post' id='prechatForm'> 
        <table class="formTable">
            <tr>
                <td><b>First Name:</b></td>
                <td><input type='text' name='liveagent.prechat:FirstNameDetail' /> </td>
            </tr>
            <tr>
                <td><b>Last Name:</b></td>
                <td><input type='text' name='liveagent.prechat:LastNameDetail' /></td>
            </tr>
            <tr>
                <td><b>Email Address:</b></td>
                <td><input type='text' name='liveagent.prechat:EmailDetail' /></td>
            </tr>
            <tr>
                <td><b>Customer Number:</b></td>
                <td><input type='text' name='liveagent.prechat:CustomerNumber' /></td>
            </tr>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td><b>Department:</b></td>
                <td>
                        <select name="liveagent.prechat.buttons">
                        <!-- Values are LiveChatButton IDs. -->
                        <option value="573U0000000TTKV">ABC Support</option>
                        <option value="573U0000000TTzY">XYZ Support</option>
                        <!--<option value="573U0000000TTzY,573U0000000TTKV">XYZ Support If Available,
                        otherwise ABC Support</option>-->
                        </select>
                </td>
            </tr>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td><input type='submit' value='Start Chat' id='prechat_submit'/></td>
            </tr>
        </table>

<!--Save Email Address to Chat Transcript-->
<input type="hidden" name="liveagent.prechat.save:EmailDetail" value="Email__c" />
<!--Save Customer Number to Chat Transcript-->
<input type="hidden" name="liveagent.prechat.save:CustomerNumber" value="Customer_Number__c" />

<!--POP OUTS-->

    <!-- ACCOUNT -->
        <!--Map To an Account if CustomerNumber variable in form equals Customer_Number__c custom field on account -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map:Account"
        value="Customer_Number__c,CustomerNumber" />
        
        <!--doFind where Customer_Number__c match = true -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Account"
        value="Customer_Number__c,true" />
        
        <!--Open the Account when we find an Exact Match -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Account"
        value="Customer_Number__c,true" />

    <!-- CONTACT -->
        <!--Map to a Contact if CustomerNumber variable and EmailDetail variable in form match to Customer_Number__c and Email field on contact-->
        <input type="hidden" name="liveagent.prechat.findorcreate.map:Contact"
        value="Customer_Number__c,CustomerNumber;Email,EmailDetail" />
        
        <!--doFind where Customer_Number__c match = true and Email match = true -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Contact"
        value="Customer_Number__c,true;Email,true" />
        
        <!--Open the Contact whne we find an Exact Match-->
        <input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Contact"
        value="Customer_Number__c,true;Email,true" />

</form> 
</div>
</apex:page>


I've been racking my brain on this all morning and not getting any farther - could use some extra brain power from the community. All thoughts and input appreciated. Thanks!
Hi all, I'm new to apex but currently going through some online courses but haven't quite grasped how I can achieve this yet...

Scenario: We have a custom object from our Zuora managed package called 'Quote Charge'. Within this object are many records. Two of these records are technically 'associated' with each other, but not using a lookup field or any traditional SFDC linking. Instead, they have a custom field that shares a unique value between these 2 'associated' records. So, both of these records have a field where the value is "20150814ABCD" for example - that field is unique to these TWO records and will never be found on any other records of this object. One of these 2 records is named "Discount", and the other one can have any varying name.

Goal: I need to, using apex I presume, find these 2 matching records based on that custom field being an exact match between the 2, and then take the discount % from a field on the record named "Discount" and apply it to another custom field on the record that isn't named "Discount"

Can anyone give me a good starting point for this/point me in the right direction? I started writing some code in a class to play around with the idea, but I don't think I'm going about it the best way. Would appreciate some feedback from the SFDC Gurus.

Many thanks,

Morgan