• James Mary
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hi!

I need to add gift cards to an opportunity if the checkbox is enabled, otherwise it will throw an error. In this case, the entered card is deactivated. In the future, I don't have the ability to change any of the opportunity field as the validation fires. How can I solve this problem?
public class OpportunityTriggerHandler {
    
         public void afterInsert (List<Opportunity> newOpportunities){
            List<String> cardNames = new List<String>();
            for(Opportunity oppItem : newOpportunities) {
                cardNames.add(oppItem.Gift_Card__c);
            }
            List<Gift_Card__c> giftCardToUpdate = [SELECT Active__c, Amount__c, Name 
                                                  FROM Gift_Card__c 
                                                  WHERE Name IN :cardNames];    
           
            for(Gift_Card__c giftCard: giftCardToUpdate ) {
                giftCard.Active__c = false;
            }
            
            update giftCardToUpdate;
        } 
        
         
        public void beforeInsert (List<Opportunity> newOpportunities){
            List<String> cardNames = new List<String>();
            for(Opportunity oppItem : newOpportunities) {
                cardNames.add(oppItem.Gift_Card__c);
        }
            List<Gift_Card__c> allGiftCards = [SELECT Active__c, Amount__c, Name 
                                           FROM Gift_Card__c 
                                           WHERE Name IN :cardNames];
            for (Opportunity newOpp: newOpportunities) {
                for(Gift_Card__c giftCard: allGiftCards ) { 
                        if (giftCard.Active__c == true) {
                        newOpp.Amount -= giftCard.Amount__c;
                     } else {
                     newOpp.Gift_Card__c.addError('Gift Card is inactive');
                         }
                    }
                }  
            }
        } 

Hi!

I have questions about the Describe Global REST endpoint (https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_describeGlobal.htm) to retrieve meta-data regarding all sObjects for a particular Salesforce organization:
  1. The response is pretty large, I am however just interested in a few fields per sObject (createable, retrievable, updateable). Is it possible to limit the response to selected fields? Using the "fields" query parameter which can be used when retrieving a specific sObject does not seem to work here.
  2. The response contains the field "maxBatchSize" with the default value 200. I am afraid that I miss some objects like this, however it seems like there is no way to increase this limit per request? The header "Sforce-Query-Options" seems not to work for this endpoint. There is also no link in the response header to potentially retrieve the next page of results.
Thanks a lot for your help!