• Alex Merwin
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 16
    Replies
Frequently our users create products and forget to create associated pricebook entries. 

I'm trying to create reporting / dashboards to show users when this happens, so they can go back and add prices. 

Idea is to create a custom field on the Product that is a formula(checkbox) field if that is TRUE if the Product has no Price book entry associated with it. 

Has anyone tried this before? 
Hey guys - 

I'm struggling to develop a Test Case for three triggers I need to promote on the Opportunity object. 

New to APEX and appreciate any help!

Here is where I've gotten for the Test Case: 
@isTest 
public class TestOLITriggers {
    static testMethod void insertNewOpportunity() {
       
       Opportunity opportunityToCreate = new Opportunity();
       
       // Do you recognize these fields?
       opportunityToCreate.StageName = 'Sourcing Demand';
       opportunityToCreate.CloseDate = '2016-01-01';
       opportunityToCreate.Account = '0015000000tVJRS';
       opportunityToCreate.Name = 'Test Opportunity Triggers';

       // Don't worry about these
       opportunityToCreate.TimeZoneSidKey    = 'America/Denver';
       opportunityToCreate.LocaleSidKey      = 'en_US';
       opportunityToCreate.EmailEncodingKey  = 'UTF-8';
       opportunityToCreate.LanguageLocaleKey = 'en_US';
       
       insert opportunityToCreate;
    }
}

And the three Opportunity Triggers. 
 
trigger OLIUpdate on Opportunity (after update) {
    Set<Id> oppIds = new Set<Id>();

    RecordType rt = [
        select Id
        from RecordType
        where Name = 'Strategic Audience Plan'
    ];

    for (Opportunity opp : Trigger.new) {
        Opportunity oldOpp = Trigger.oldMap.get(opp.Id);
        if (
            opp.StageName == 'Notify Demand' &&
            oldOpp.StageName != opp.StageName &&
            opp.RecordTypeId == rt.Id
        ) {
            oppIds.add(opp.Id);
        }
    }

    if (!oppIds.isEmpty()) {
        List<OpportunityLineItem> oliList = [
            select Campaign_Status__c,
                INTL_Demand_Approval__c
            from OpportunityLineItem
            where OpportunityId in :oppIds
        ];

        for (OpportunityLineItem oli : oliList) {
            if (oli.INTL_Demand_Approval__c != 'Local Demand must approve buyer before Launch Ticket can be deployed') {
                oli.Campaign_Status__c = 'Buyer Approved, Ready to Launch';
            } else {
                oli.Campaign_Status__c = 'Buyer Approved, Pending Local Demand Approval';
            }
        }

        update oliList;
    }
}

trigger OLIUpdate_SAP_SendLaunchTickets on Opportunity (after update) {
    Set<Id> oppIds = new Set<Id>();

    for (Opportunity opp : Trigger.new) {
        Opportunity oldOpp = Trigger.oldMap.get(opp.Id);
        if (
            opp.StageName == 'Deploy Launch Tickets' &&
            oldOpp.StageName != opp.StageName 
        ) {
            oppIds.add(opp.Id);
        }
    }

    if (!oppIds.isEmpty()) {
        List<OpportunityLineItem> oliList = [
            select Campaign_Status__c
            from OpportunityLineItem
            where OpportunityId in :oppIds
        ];

        for (OpportunityLineItem oli : oliList) {
            oli.Campaign_Status__c = 'Buyer Approved, Ready to Launch';
        }

        update oliList;
    }
}


 
trigger OLIUpdate_SAP_BuyerApproval on Opportunity (after update) {
    Set<Id> oppIds = new Set<Id>();

    for (Opportunity opp : Trigger.new) {
        Opportunity oldOpp = Trigger.oldMap.get(opp.Id);
        if (
            opp.StageName == 'Responded to Buyer' &&
            oldOpp.StageName != opp.StageName
        ) {
            oppIds.add(opp.Id);
        }
    }

    if (!oppIds.isEmpty()) {
        List<OpportunityLineItem> oliList = [
            select Campaign_Status__c
            from OpportunityLineItem
            where OpportunityId in :oppIds
        ];

        for (OpportunityLineItem oli : oliList) {
            oli.Campaign_Status__c = 'Buyer Approval Needed';
        }

        update oliList;
    }
}


 
When users have added Products to an Opportunity, we frequently have a need to reference information about the Products out of SalesForce. Therefore, we want to have an Export functionality from the Opportunity Page, exporting details about the Products associated with that Opportunity. 

I've tried a few routes for this, but haven't found a solution yet. Custom Links to Reports, with a Product ID passed in the query string of the URL as PV0 works well, but only for a single product (so, I've got that 'export' button added to the Product Detail page, but then users would have to pull reports one by one, waste of time as we sometimes have 25+ products associated with one opportunity). 

Is there some APEX I could use to populate a custom field on the Opportunity object (Export_All_Inventory_Pkg_Reference__c) with all of the Product_ID__c values associated with that opportunity (note this is a Custom system generated ID field, on the Opportunity Product object)? Each Product_ID__c would need to be comma delimited. 

If so, I could add a Custom Link button to the Opportunity detail page for 'Export Products', and populate it with this Export_All_Inventory_Pkg_Reference__c value, and I think it would work. 

FYI, been trying to figure this out on another thread too, but a different method.  (https://developer.salesforce.com/forums/ForumsMain?id=906F0000000MGQcIAO)
Hi everyone - 

I'm trying to modify some APEX used for a different purpose for this, and I think I'm getting off track. 

There is a custom text field called SpX_Product_ID__c on the OpportunityLineItem object. I need to populate a new field, Export_All_Inventory_Pkg_Reference__c , with all SpX_Product_ID__c values for OLI associated with the same Opportunity. 

I will then use the Export_All_Inventory_Pkg_Reference__c to populate a Custom Link on the OLI Detail Page so users can view a report of all Products associated with this Opportunity with one click. 

Thanks for your help!
 
trigger ExportPkgRef on OpportunityLineItem (after update, after insert) {
    Set<Id> oppIds = new Set<Id>();

    for (OpportunityLineItem opp : Trigger.new) {
        OpportunityLineItem oldOpp = Trigger.oldMap.get(opp.Id);
        if (
            opp.Opportunity.ID = opp.Opportunity.ID &&
            oldOpp.Opportunity.ID != opp.Opportunity.ID
        ) {
            oppIds.add(opp.Id);
        }
    }

    if (!oppIds.isEmpty()) {
        List<OpportunityLineItem> oliList = [
            select SpX_Product_ID__c
            from OpportunityLineItem
            where OpportunityLineItemId in :oppIds
        ];

        for (OpportunityLineItem oli : oliList) {
            oli.SpX_Product_ID__c = SpX_Product_ID__c;
        }

        update oliList;
    }
}

 
Hello - 

I am trying to create an efficient means for users to Export all Products that are associated with a given Opportunity. 

I've attempted this by: 
  • Creating a Template Report for the export, and putting it in a Public Folder
  • Creating a Custom Field on the Product Object called 'Product ID', because for some reason the system generated SF ID for Products isn't included in the Reporting module as a selectable field / filter. 
  • Created a cross-object formula field on the Opportunity Product object, referencing the Custom 'Product ID' field from the associated Product
  • Added a List Button to the Opportunity Product object, with the following settings. The ID in the URL references the Template Report. User-added image
When I select products and click 'Export', I get this error: 
Unable to Access Page
The value of the "rt" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information. 


Looking at the URL it doesn't seem as if the query string is populating correctly:

https://DOMAIN.my.salesforce.com/00O38000004J9f3?pv0=&lid=00b38000001Co33&eid=0063800000ZamzO&ic=1&retURL=%2F0063800000ZamzO&wrapMassAction=1&scontrolCaching=1&linkToken=VmpFPSxNakF4TlMweE1pMHdNVlF3T1RveE56b3pNaTQwT0RsYSwzMm83WnM3Z09XT204ZGs5UWFGTk1YLFlXWmtNR0po&autoMapValues=1​

I was hoping that by checking multiple boxes, SalesForce would populate multiple instances of the Custom Field 'Product ID' as a filter for the custom report. 

Can anyone help? 


User-added image


User-added image



 
Hello - 

I'm new to APEX and struggling with what should be a pretty easy ask I think. 

When a user updates the StageName field on the Opportunity standard object to 'Notify Demand', I need all OpportunityLineItems (standard object) associated with this Opportunity to have a picklist custom field named 'Campaign Status' updated to 'Buyer Approval Needed'. 

It is my intent to schedule a workflow rule to trigger based off the update of the OpportunityLineItem object, with a lot of merged fields from that object. So, you update the StageName at the Opportunity level, and a series of customized emails deploys, one per OpportunityLineItem. 

Here's what I have so far for the Trigger: 
 
trigger update on Opportunity (before insert, before update){

  List<ID> OppIds = New List<ID>();

  for(Opportunity o : Trigger.new){
    if(o.StageName == 'Notify Demand' && o.OpportunityLineItem__c != null){
      OppIds.add(o.OpportunityLineItem__c);
    }
  }

  List<OpportunityLineItem__c> oppList = [SELECT id, Campaign_Status__c FROM OpportunityLineItem WHERE id in :OppIds];
  for(integer i = 0 ; i < oppList.size(); i++){
    oppList[i].Campaign_Status__c = ‘Buyer Approval Needed’;
  }

  update oppList;
}

 
Frequently our users create products and forget to create associated pricebook entries. 

I'm trying to create reporting / dashboards to show users when this happens, so they can go back and add prices. 

Idea is to create a custom field on the Product that is a formula(checkbox) field if that is TRUE if the Product has no Price book entry associated with it. 

Has anyone tried this before? 
Hey guys - 

I'm struggling to develop a Test Case for three triggers I need to promote on the Opportunity object. 

New to APEX and appreciate any help!

Here is where I've gotten for the Test Case: 
@isTest 
public class TestOLITriggers {
    static testMethod void insertNewOpportunity() {
       
       Opportunity opportunityToCreate = new Opportunity();
       
       // Do you recognize these fields?
       opportunityToCreate.StageName = 'Sourcing Demand';
       opportunityToCreate.CloseDate = '2016-01-01';
       opportunityToCreate.Account = '0015000000tVJRS';
       opportunityToCreate.Name = 'Test Opportunity Triggers';

       // Don't worry about these
       opportunityToCreate.TimeZoneSidKey    = 'America/Denver';
       opportunityToCreate.LocaleSidKey      = 'en_US';
       opportunityToCreate.EmailEncodingKey  = 'UTF-8';
       opportunityToCreate.LanguageLocaleKey = 'en_US';
       
       insert opportunityToCreate;
    }
}

And the three Opportunity Triggers. 
 
trigger OLIUpdate on Opportunity (after update) {
    Set<Id> oppIds = new Set<Id>();

    RecordType rt = [
        select Id
        from RecordType
        where Name = 'Strategic Audience Plan'
    ];

    for (Opportunity opp : Trigger.new) {
        Opportunity oldOpp = Trigger.oldMap.get(opp.Id);
        if (
            opp.StageName == 'Notify Demand' &&
            oldOpp.StageName != opp.StageName &&
            opp.RecordTypeId == rt.Id
        ) {
            oppIds.add(opp.Id);
        }
    }

    if (!oppIds.isEmpty()) {
        List<OpportunityLineItem> oliList = [
            select Campaign_Status__c,
                INTL_Demand_Approval__c
            from OpportunityLineItem
            where OpportunityId in :oppIds
        ];

        for (OpportunityLineItem oli : oliList) {
            if (oli.INTL_Demand_Approval__c != 'Local Demand must approve buyer before Launch Ticket can be deployed') {
                oli.Campaign_Status__c = 'Buyer Approved, Ready to Launch';
            } else {
                oli.Campaign_Status__c = 'Buyer Approved, Pending Local Demand Approval';
            }
        }

        update oliList;
    }
}

trigger OLIUpdate_SAP_SendLaunchTickets on Opportunity (after update) {
    Set<Id> oppIds = new Set<Id>();

    for (Opportunity opp : Trigger.new) {
        Opportunity oldOpp = Trigger.oldMap.get(opp.Id);
        if (
            opp.StageName == 'Deploy Launch Tickets' &&
            oldOpp.StageName != opp.StageName 
        ) {
            oppIds.add(opp.Id);
        }
    }

    if (!oppIds.isEmpty()) {
        List<OpportunityLineItem> oliList = [
            select Campaign_Status__c
            from OpportunityLineItem
            where OpportunityId in :oppIds
        ];

        for (OpportunityLineItem oli : oliList) {
            oli.Campaign_Status__c = 'Buyer Approved, Ready to Launch';
        }

        update oliList;
    }
}


 
trigger OLIUpdate_SAP_BuyerApproval on Opportunity (after update) {
    Set<Id> oppIds = new Set<Id>();

    for (Opportunity opp : Trigger.new) {
        Opportunity oldOpp = Trigger.oldMap.get(opp.Id);
        if (
            opp.StageName == 'Responded to Buyer' &&
            oldOpp.StageName != opp.StageName
        ) {
            oppIds.add(opp.Id);
        }
    }

    if (!oppIds.isEmpty()) {
        List<OpportunityLineItem> oliList = [
            select Campaign_Status__c
            from OpportunityLineItem
            where OpportunityId in :oppIds
        ];

        for (OpportunityLineItem oli : oliList) {
            oli.Campaign_Status__c = 'Buyer Approval Needed';
        }

        update oliList;
    }
}


 
Hi everyone - 

I'm trying to modify some APEX used for a different purpose for this, and I think I'm getting off track. 

There is a custom text field called SpX_Product_ID__c on the OpportunityLineItem object. I need to populate a new field, Export_All_Inventory_Pkg_Reference__c , with all SpX_Product_ID__c values for OLI associated with the same Opportunity. 

I will then use the Export_All_Inventory_Pkg_Reference__c to populate a Custom Link on the OLI Detail Page so users can view a report of all Products associated with this Opportunity with one click. 

Thanks for your help!
 
trigger ExportPkgRef on OpportunityLineItem (after update, after insert) {
    Set<Id> oppIds = new Set<Id>();

    for (OpportunityLineItem opp : Trigger.new) {
        OpportunityLineItem oldOpp = Trigger.oldMap.get(opp.Id);
        if (
            opp.Opportunity.ID = opp.Opportunity.ID &&
            oldOpp.Opportunity.ID != opp.Opportunity.ID
        ) {
            oppIds.add(opp.Id);
        }
    }

    if (!oppIds.isEmpty()) {
        List<OpportunityLineItem> oliList = [
            select SpX_Product_ID__c
            from OpportunityLineItem
            where OpportunityLineItemId in :oppIds
        ];

        for (OpportunityLineItem oli : oliList) {
            oli.SpX_Product_ID__c = SpX_Product_ID__c;
        }

        update oliList;
    }
}

 
Hello - 

I'm new to APEX and struggling with what should be a pretty easy ask I think. 

When a user updates the StageName field on the Opportunity standard object to 'Notify Demand', I need all OpportunityLineItems (standard object) associated with this Opportunity to have a picklist custom field named 'Campaign Status' updated to 'Buyer Approval Needed'. 

It is my intent to schedule a workflow rule to trigger based off the update of the OpportunityLineItem object, with a lot of merged fields from that object. So, you update the StageName at the Opportunity level, and a series of customized emails deploys, one per OpportunityLineItem. 

Here's what I have so far for the Trigger: 
 
trigger update on Opportunity (before insert, before update){

  List<ID> OppIds = New List<ID>();

  for(Opportunity o : Trigger.new){
    if(o.StageName == 'Notify Demand' && o.OpportunityLineItem__c != null){
      OppIds.add(o.OpportunityLineItem__c);
    }
  }

  List<OpportunityLineItem__c> oppList = [SELECT id, Campaign_Status__c FROM OpportunityLineItem WHERE id in :OppIds];
  for(integer i = 0 ; i < oppList.size(); i++){
    oppList[i].Campaign_Status__c = ‘Buyer Approval Needed’;
  }

  update oppList;
}