• Daniel Grabowski
  • NEWBIE
  • 15 Points
  • Member since 2015
  • Lead Salesforce Engineer
  • Chief


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 7
    Replies
I think the challenge on this trailhead is broken: https://trailhead.salesforce.com/modules/apex_integration_services/units/apex_integration_rest_callouts

When I go to https://th-apex-http-callout.herokuapp.com/animals/:id i get:
{"animal":{"id":0,"name":"","eats":"","says":""}}

When I view the logs after clicking the "Check Challenge" button, the integer it is looking for is 99.  It seems like the endpoint is not returning the correct data and completing this is currently impossible.
I'm building a visualforce page using SLDS0121, and the Docked Composer doesn't seem to show up right.  I directly copy/pasted the Base version, it just shows up inside of the page (at the bottom) without any formatting (header color, container box, etc).  According to the docs it is stable, and I tried putting the code just about everywhere I can think of ( inside <div class="slds"> and/or <div class="myapp">, etc.) .  

Anyone else having trouble with this?

https://www.lightningdesignsystem.com/components/docked-composer/
public void onBeforeUpdate(List<Opportunity> newMap){
    Set<String> oppIds = new Set<String>();
    for(Opportunity opp: newMap){
        oppIds.add(opp.id);
    }
    
    if(oppIds.size() > 0 && oppIds != null){
       //get all record of product with  Opp Id
        List<OpportunityLineItem> productList =  [SELECT Product2.m_ProductGroup__r.Name, OpportunityId, Opportunity.shipDate__c, 
                                                  Opportunity.return_date__c FROM OpportunityLineItem
                                                  WHERE OpportunityId IN :oppIds
                                                  AND IsDeleted = false              
                                                 ];  
        if(productList.size() > 0 && productList !=null){ 
            for(OpportunityLineItem product: productList){
                totalUsed = 0;
                String name =  product.Product2.m_ProductGroup__r.Name;
                Date startDate = product.Opportunity.shipDate__c;
                Date endDate = product.Opportunity.return_date__c;
                
                if(name != ''){
                    totalUsed  = getSum(name, startDate, endDate);
                    if( totalUsed <= 30 ){ 
                        for(Opportunity opp: newMap) { 
                            opp.m_enableproduct__c = true; 
                        }
                    }                 
                }
            }   
        }
    }
} //end BeforeUpdate
    
    
private Decimal getSum(String productName, Date startDate, Date endDate){
    Decimal sum = 0;        
    List<Opportunity> dataList = new List<Opportunity>();
    List<OpportunityLineItem> productList = new List<OpportunityLineItem>();
    dataList = [SELECT id, shipDate__c, return_date__c FROM Opportunity WHERE shipDate__c >= :startDate AND return_date__c <= :endDate];
    if(dataList != null  && dataList.size() > 0){
        for(Opportunity opp :dataList){
            productList = [SELECT Quantity FROM OpportunityLineItem
                           WHERE OpportunityId =:opp.id  
                           AND Product2.m_ProductGroup__r.Name =: productName
                           AND IsDeleted = false 
                          ];                
            if(productList != null && productList.size() > 0 ){
                for(OpportunityLineItem addTemp :productList){
                    sum += addTemp.Quantity;         
                }  
            }
        }           
        system.debug('sum' + sum);
    }
    return sum;   
}
Hi Everyone help me to get output.

WHERE shipDate__c >= :startDate  AND return_date__c <= :endDate 

In the above code startDate & endDate retrives the data (already Inserted Record) from db.
for eg:
startDate = 20-03-2021
endDate = 16-04-2021

WHERE shipDate__c >= :20-03-2021 AND return_date__c <= :16-04-2021

but what i need is, While editing the record by changing startDate, it retrives the entered data before saving in db. 
for eg:
startDate = 26-03-2021
 
WHERE shipDate__c >= :26-03-2021 AND return_date__c <= :16-04-2021

Hope someone will help

Thank you 
I havea requirement where  I have to update a contacts custom rich text area when a picklist value changes in Opportunity.
The trick is when the picklist changes on Opp, there are three values from opportunity for ex A,B & C should be concatenated and updated as hyperlink in the custom field on contact.

The hyperlink should redirect to the orignal Opp record.
Also the rich text field should become null once field A on contact is not equal to null.

Also the opp has look up to contact. So for a new Opp should be its own line, whilst an update should over write the existing link.

ANY HELP is much appreciated.
In my application there is  a custom object related to the Product2. What I need is to fetch some fields of OpportunityLineItem  and  some fields of custom object which is related to Product2. I am executing the following queries : 
1. SELECT ID from RelatedCustomObject where Product2.Id IN (SELECT ProductID from OpportunityLineItem where OpportunityID = '123')
2. SELECT quantity from  OpportunityLineItem where OpportunityID = '123'

But in the scenerio where OpportunityLineItem has 7 records, out of which 2 uses same Product , the first query is eliminating the duplicate ones due to IN clause and giving results for the unique ones.But I need to fetch them all.Could anyone please suggest what can be done in this case?User-added image 

I have a simple apex method that generates a short ID and a trigger that attaches that ID to a custom text field on my Account object. 

In the configuration for this custom field, I specified that this field should be unique. 

There is a very slight chance that the method that creates my ID will create a duplicate. So, I'm looking for a way that my trigger can simply try again when Salesforce detects that the ID I just tried to put into my record is a duplicate. EventBus.RetryableException (https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_apex_refire.htm) seems like the right path to take, but I'm having trouble either getting it to work properly or creating a test that can validate whether it is working. 

Method: 
 

public class GeneratePlanID {
    public static String generateRandomID(Integer len) {
        final String chars = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789';
        String randStr = '';
        while (randStr.length() < len) {
           Integer idx = Math.mod(Math.abs(Crypto.getRandomInteger()), chars.length());
           randStr += chars.substring(idx, idx+1);
        }
        return randStr;
    }
}
Trigger:
trigger PlanIDTrigger on Account (before insert, before update) {
    try {
        for (Account a : Trigger.New) {
            if (Trigger.isInsert || a.PlanID__c == null) {
                String newID = GeneratePlanID.generateRandomID(4);
                a.PlanID__c = newID;
            }
        }
    } catch (Exception e) {
        if (EventBus.TriggerContext.currentContext().retries < 3) {
            throw new EventBus.RetryableException('Exception found retrying plan ID assignment', e);
        } else {
            System.debug('PlanID assignment reached max retries');
        }
    }
}
Not super helpful tests right now: 
@isTest
public class TestPlanIDTrigger {
    @isTest static void TestCreateNewAccount() {
        Account acct = new Account(Name='Test Account');
        
        Test.startTest();
        Database.SaveResult result = Database.insert(acct, false);
        Test.stopTest();
        
        System.assert(result.isSuccess());
        
        Account resultPlanID = [SELECT PlanID__c FROM Account WHERE ID = :result.getId()];
        System.assert(resultPlanID != null);
    }
    
    @isTest static void TestDuplicateAccountPlanID() {        
        
        Test.startTest();
        Account[] accts = new List<Account>{
            new Account(Name='Test Account 1', PlanID__c='ABCD'),
            new Account(Name='Test Account 2', PlanID__c='ABCD')
        };
        Database.SaveResult[] result = Database.insert(accts, false);
        Test.stopTest();
        
        for (Database.SaveResult sr : result) {            
            if (sr.isSuccess()) {
                System.debug('Successful insert of PlanID');
                System.assert(sr.isSuccess());
            } else {
                for (Database.Error err : sr.getErrors()) {
                    System.debug('Failed insert of PlanID');
                    System.debug(err.getStatusCode() + ': ' + err.getMessage());
                }
                System.assert(!sr.isSuccess());
                System.assert(sr.getErrors().size() > 0);
            }
        }        
    }
}

 
I'm building a visualforce page using SLDS0121, and the Docked Composer doesn't seem to show up right.  I directly copy/pasted the Base version, it just shows up inside of the page (at the bottom) without any formatting (header color, container box, etc).  According to the docs it is stable, and I tried putting the code just about everywhere I can think of ( inside <div class="slds"> and/or <div class="myapp">, etc.) .  

Anyone else having trouble with this?

https://www.lightningdesignsystem.com/components/docked-composer/

Hi,

How do we handle the attachments in inbound mail? I need to capture email attachment as attachment in Salesforce.  I had created Salesforce (case) records from the contents of email but struggling to handle attachment. Any detail update on this is highly appreciated.

How we can handle this through Apex EMAIL SERVICES
 
Thanks
Nazeer

Message Edited by Nazeer on 11-23-2007 07:35 AM

  • November 21, 2007
  • Like
  • 0