• DM 13
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
Hi 

Is there a way to change Salesforce out-of-box favicons colour to white instead of grey? I have changed the background using Branding and Themes but unsure how to change the colour of Favicons

SF Favicons
  • August 24, 2022
  • Like
  • 0
Hi,

I am making an endpoint call and trying to extract the value from JSON.I am getting the parser error. What I am doing wrong here?

******* JSON Response *******
{
    "hitCount": 6,
    "noticeList": [
        {
            "score": 1,
            "item": {
                "id": "ec3fd49a-77d1-4bed-9991-8db58311c0bd",
                "parentId": null,
                "noticeIdentifier": "BIP683856785",
                "title": "GB-Newcastle: T21/0084 CRM Solution",
                "description": "The University is currently reviewing solution when/how to intervene.",
                "sector": "",
                "cpvCodes": "48445000 48400000",
                "cpvCodesExtended": "48000000 48400000 48440000",
                "region": "North East",
                "regionText": "North East",
                "start": "2022-05-31T00:00:00Z",
                "end": "2025-05-30T00:00:00Z"
            }
        },
        {
            "score": 1,
            "item": {
                "id": "8dd64188-3fa2-487f-adf9-8184edf4418d",
                "parentId": "d105359a-e9c8-4657-ae14-5503fdd6f733",
                "noticeIdentifier": "TORB001-DN605082-46428489",
                "title": "Parks, Street Scene and Green Infrastructure Management System for SWISCo",
                "description": "A (2) phases",
                "cpvDescription": "Software package and information systems",
                "cpvDescriptionExpanded": "Software package and information systems",
                "sector": "",
                "cpvCodes": "48000000",
                "cpvCodesExtended": "48000000",
                "region": "North East,North West,Yorkshire and The Humber,East Midlands,West Midlands,East of England,London,South East,South West",
                "regionText": "North East,North West,Yorkshire and The Humber,East Midlands,West Midlands,East of England,London,South East,South West",
                "start": "2022-06-06T00:00:00Z",
                "end": "2025-06-06T00:00:00Z"
            }
        }
    ],
    "maxHits": 1000,
    "byRegion": {
        "items": [
            {
                "key": "East Midlands",
                "value": "3"
            },
            {
                "key": "Northern Ireland",
                "value": "1"
            }
        ],
        "other": 0
    },
    "byType": {
        "items": [
            {
                "key": "Contract",
                "value": 6
            },
            {
                "key": "PreProcurement",
                "value": 0
            }
        ],
        "other": 0
    },
    "byStatus": {
        "items": [
            {
                "key": "Open",
                "value": 6
            },
            {
                "key": "Awarded",
                "value": 0
            }
        ],
        "other": 0
    }
}
**********************CLASS**************

public class CFSearchCalloutClient extends CalloutClient{

    private static final String BASE_ENDPOINT = 'https://www.contractsfinder.service.gov.uk';
    //private static final String TOKEN = '2YotnFZFEjr1zCsicMWpAA';
    private static final String SUCCESS_CHARGE_STATUS = 'succeeded';
    private static String ENDPOINT ='/Searches/Search';
    private String searchCriteriaRequest;
   
    public CFSearchCalloutClient() {}
   
    public class SearchCriteriaResponseList {
        public List<NoticeSearchResponse> noticeSearchResponses;
        public SearchCriteriaResponseList(){
            system.debug('** SearchCriteriaResponseList constrctor **');
        }
    }
      
    public class NoticeSearchResponse {
        public Integer hitCount;
        //public List<NoticeList> nList;
        public Integer maxHits;
        //public NoticeByRegion byRegion;
        //public NoticeByType byType;
        //public NoticeByStatus byStatus;
       
        public NoticeSearchResponse(){
            system.debug('** NoticeSearchResponse constrctor **');
        }
       }

public class NoticeByRegion{
        public Integer other;
        public Map<String, Integer> items;
    }
   
    public class NoticeByType{
        public Integer other;
        public Map<NoticeType, Integer> itemTypes;
    }
   
    public class NoticeByStatus{
        public Integer other;
        public Map<NoticeStatus, Integer> itemStatuses;
    }

    //NoticeSearchResponse
    public NoticeSearchResponse searchCriteria(String includeKeyword, String type, String status) {
        system.debug('*** Start searchCriteria ***');
        generateRequest(includeKeyword, type, status);
        createRequest();
        //method from CalloutClient class
        doCallout();
        System.debug('**** handleResponse --- ');
        return handleResponse();
    }
   
    public override Object getResponseObject() {
        system.debug('*** Start getResponseObject ****');
       
        NoticeSearchResponse nsResponse = new NoticeSearchResponse();
       
        /*NoticeList nList;
        List<NoticeList> nLists = new List<NoticeList>();
        NoticeListItem nli;
        List<NoticeListItem> nlItems= new List<NoticeListItem>();*/
       
        system.debug('Get String Response BODY >> -- '+(SearchCriteriaResponseList)JSON.deserialize('{'+getResponseBody()+'}', SearchCriteriaResponseList.class));
        try {
            SearchCriteriaResponseList data = (SearchCriteriaResponseList)JSON.deserialize('{'+getResponseBody()+'}', SearchCriteriaResponseList.class);
            System.debug('$$$ SearchCriteriaResponseList $$$ '+data );
            //nsResponse.hitCount = data.hitCount;
            //nsResponse.maxHits = data.maxHits;
             for(NoticeSearchResponse item: data.noticeSearchResponses){
                 nsResponse.hitCount = item.hitCount;
                 nsResponse.maxHits = item.maxHits;
                 /*for(NoticeList nl:item.nList){
                     nList.score = nl.score;
                     for(NoticeListItem nlItem: nl.ntItems){
                         nli.id = nlItem.id;
                         nli.description = nlItem.description;
                         nli.noticeType = nlItem.noticeType;
                         nli.noticeStatus = nlItem.noticeStatus;
                         nli.organisationName = nlItem.organisationName;
                         nlItems.add(nli);
                     }
                     nLists.add(nList);
                 }*/
                 //nsResponse.maxHits = item.maxHits;
             system.debug('*** nsResponse -- '+nsResponse);
             //nsResponse.nList.score = data.noticeSearchResponses.
             }
                system.debug('*** End getResponseObject ***');
                return nsResponse;
        } catch (JSONException ex) {
            system.debug('*** End getResponseObject try-catch()***');
            throw new JSONException('Response deserialization has failed.');
        }
    }
    private void generateRequest(String includeKeyword, String ntName, String ntStatus) {
      system.debug('*** Start generateRequest ***');      
        searchCriteriaRequest = '"searchCriteria": {'+
                                                  '      "types": ['+
                                                  '             "'+ntName+'"'+
                                                  '      ],'+
                                                  '      "statuses": ['+
                                                  '             "'+ntStatus+'"'+
                                                  '      ],'+
                                                  '      "keyword": "'+includeKeyword+'"'+
   
                                                         '},'+
                                                         '"size": 1000';
        system.debug('noticeType = '+ntName+' noticeStatus = '+ntStatus);
        system.debug('searchCriteriaRequest = '+searchCriteriaRequest);
        system.debug('*** End generateRequest ***');
    }
    private void createRequest() {
        System.debug('*** Start createRequest() ***');
        request = super.createRequest(HTTP_METHOD_POST);
        request.setEndpoint(BASE_ENDPOINT + ENDPOINT);
        request.setHeader('Content-Type', HEADER_CONTENT_TYPE_APPLICATION_JSON);
        request.setBody(searchCriteriaRequest);
       
        System.debug(' REQUEST >>>>'+searchCriteriaRequest);
        System.debug('*** End createRequest() ***');
    }
    private NoticeSearchResponse handleResponse()handleResponse() {
        system.debug('*** Start handleResponse ****');
        if (isStatusCodeOk()) {
           
            System.debug('*** End handleResponse() ***Next statement is to return responseObject()');
            return (NoticeSearchResponse)getResponseObject();
           
        } else {
            System.debug('*** End handleResponse() try-catch() ***');
            throw new CalloutClientException('Invalid status code: ' + getResponseStatusCode());
       }
    }
}

Regards
Divya
  • April 27, 2022
  • Like
  • 0
Hi,

I need to make an apex REST callout to a 3rd party web service. I was wondering if there is a way to add filter while making callouts, so I get only required data by filtering it out. Can someone shed some light here please.

Thanks
  • October 05, 2021
  • Like
  • 0
Hi, 

I have below Apex code to send notification to case owner when an Email is transferred from one case to another. This was working fine before enabling Enhanced Email feature. But once its enbled it's throwing below error -

EXCEPTION - SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, EmailMessageTrigger: execution of AfterInsert
caused by: System.NullPointerException: Attempt to de-reference a null object

public static String transferEmailsToTargetCase(Id originCaseId, Id targetCaseId, Set<Id> emailIds) {
        System.debug('** transferEmailsToTargetCase start **');
        Map<Id, EmailMessage> oldEmailId2newEmail = new Map<Id, EmailMessage>();
        Case originCase = [
            SELECT Id, CaseNumber, Subject,
                (SELECT Id, FromAddress, Incoming, ToAddress, Subject, TextBody, ParentId, BccAddress,
                    CcAddress, FromName, Headers, HtmlBody, MessageDate, ReplyToEmailMessageId,
                    Source_Case__c, Status
                FROM EmailMessages
                WHERE Id IN :emailIds)
            FROM Case
            WHERE Id = :originCaseId
        ];
        
        Case targetCase = new case();
        if(targetCaseId!=null){
            targetCase = [
                SELECT Id, ownerId, owner.email, owner.name, CaseNumber, Subject
                    FROM Case
                    WHERE Id = :targetCaseId
            ];
        }
       
        if(originCase.EmailMessages.isEmpty()) {
            return Label.No_emails_under_source_Case;
        }   

        for(EmailMessage em : originCase.EmailMessages) {
            EmailMessage emCloned = em.clone();
            emCloned.ParentId = targetCaseId;
            if(String.isBlank(em.Source_Case__c)) {
                emCloned.Source_Case__c = originCaseId;
            }
            oldEmailId2newEmail.put(em.Id, emCloned);
        }


        try {
            EmailMessageTriggerHelper.CHECK_EDIT_RIGHTS_ON_CASE = false;
            insert oldEmailId2newEmail.values();
            copyOverAttachmentsToNewEmail(oldEmailId2newEmail);
            EmailMessageTriggerHelper.ALLOW_DELETION = true;
            delete originCase.EmailMessages;
            
            //send email to new case owner to confirm emails moved
            if(targetCaseId!=null){
                //update URL for live
                string cssProdOrgURL = Org_Settings__c.getOrgDefaults().ORG_URL__c+'/';
                system.debug('cssProdOrgURL --'+ cssProdOrgURL);
                
                string emailBodyConfirmMove = '<html><head><style> table {font-family: arial, sans-serif;border-collapse: collapse;}td, th {border: 1px solid #dddddd;text-align: left;padding: 8px;}tr:nth-child(even) {background-color: #F1F1F1;}</style></head><body><p>Hi ';
                emailBodyConfirmMove+=targetCase.owner.name+',</p><br/><p>THIS IS A SYSTEM GENERATED EMAIL.</p><p>Please be advised that one or more emails have been moved to the ';
                emailBodyConfirmMove+='<a href="'+cssProdOrgURL+targetCase.id+'">'+targetCase.CaseNumber+'</a> Case, and it requires your review.</p><br/><p>Number of Emails: ';
                emailBodyConfirmMove+=originCase.EmailMessages.size()+'</p><p>Case Subject: ';
                emailBodyConfirmMove+='<a href="'+cssProdOrgURL+targetCase.id+'">'+targetCase.Subject+'</a></p><br/><table ><tr ><th>Subject</th><th>From Name</th><th>From Address</th><th>Message Date</th></tr>';
                
                for(EmailMessage emCloned :oldEmailId2newEmail.values()){
                    emailBodyConfirmMove+='<tr><td><a href="'+cssProdOrgURL+emCloned.id+'">'+emCloned.Subject+'</a></td>';
                    emailBodyConfirmMove+='<td>'+emCloned.FromName+'</td>';
                    emailBodyConfirmMove+='<td>'+emCloned.FromAddress+'</td>';
                    emailBodyConfirmMove+='<td>'+emCloned.MessageDate+'</td></tr>';
                    
                }
                emailBodyConfirmMove+='</table>';
                if(string.valueOf(targetCase.OwnerId).startsWith('005')){//owner is user not queue
                    List<Messaging.SingleEmailMessage> lstMsgs = new List<Messaging.SingleEmailMessage>();
                    Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
                    user targetOwner = [SELECT Id, email FROM user WHERE id=:targetCase.OwnerId AND email != null];
                    msg.setToAddresses(new List<String>{targetOwner.email});
                    msg.setHTMLbody(emailBodyConfirmMove);
                    msg.setSubject('Emails transferred to CASE -'+targetCase.CaseNumber);

                    lstMsgs.add(msg);
                    Messaging.SendEmailResult[] r = Messaging.sendEmail(lstMsgs);
                    
                }
            }
            
            
        } catch(Exception e) {
  system.debug('** EXCEPTION - '+e.getMessage());
            return e.getMessage();
        }
        
        return Label.Success_msg;
    }
  • September 24, 2021
  • Like
  • 0
Is there any possible way in which we can copy one dev orgs to other dev org?or can we have more than one dev orgs?
Hi, 

I have below Apex code to send notification to case owner when an Email is transferred from one case to another. This was working fine before enabling Enhanced Email feature. But once its enbled it's throwing below error -

EXCEPTION - SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, EmailMessageTrigger: execution of AfterInsert
caused by: System.NullPointerException: Attempt to de-reference a null object

public static String transferEmailsToTargetCase(Id originCaseId, Id targetCaseId, Set<Id> emailIds) {
        System.debug('** transferEmailsToTargetCase start **');
        Map<Id, EmailMessage> oldEmailId2newEmail = new Map<Id, EmailMessage>();
        Case originCase = [
            SELECT Id, CaseNumber, Subject,
                (SELECT Id, FromAddress, Incoming, ToAddress, Subject, TextBody, ParentId, BccAddress,
                    CcAddress, FromName, Headers, HtmlBody, MessageDate, ReplyToEmailMessageId,
                    Source_Case__c, Status
                FROM EmailMessages
                WHERE Id IN :emailIds)
            FROM Case
            WHERE Id = :originCaseId
        ];
        
        Case targetCase = new case();
        if(targetCaseId!=null){
            targetCase = [
                SELECT Id, ownerId, owner.email, owner.name, CaseNumber, Subject
                    FROM Case
                    WHERE Id = :targetCaseId
            ];
        }
       
        if(originCase.EmailMessages.isEmpty()) {
            return Label.No_emails_under_source_Case;
        }   

        for(EmailMessage em : originCase.EmailMessages) {
            EmailMessage emCloned = em.clone();
            emCloned.ParentId = targetCaseId;
            if(String.isBlank(em.Source_Case__c)) {
                emCloned.Source_Case__c = originCaseId;
            }
            oldEmailId2newEmail.put(em.Id, emCloned);
        }


        try {
            EmailMessageTriggerHelper.CHECK_EDIT_RIGHTS_ON_CASE = false;
            insert oldEmailId2newEmail.values();
            copyOverAttachmentsToNewEmail(oldEmailId2newEmail);
            EmailMessageTriggerHelper.ALLOW_DELETION = true;
            delete originCase.EmailMessages;
            
            //send email to new case owner to confirm emails moved
            if(targetCaseId!=null){
                //update URL for live
                string cssProdOrgURL = Org_Settings__c.getOrgDefaults().ORG_URL__c+'/';
                system.debug('cssProdOrgURL --'+ cssProdOrgURL);
                
                string emailBodyConfirmMove = '<html><head><style> table {font-family: arial, sans-serif;border-collapse: collapse;}td, th {border: 1px solid #dddddd;text-align: left;padding: 8px;}tr:nth-child(even) {background-color: #F1F1F1;}</style></head><body><p>Hi ';
                emailBodyConfirmMove+=targetCase.owner.name+',</p><br/><p>THIS IS A SYSTEM GENERATED EMAIL.</p><p>Please be advised that one or more emails have been moved to the ';
                emailBodyConfirmMove+='<a href="'+cssProdOrgURL+targetCase.id+'">'+targetCase.CaseNumber+'</a> Case, and it requires your review.</p><br/><p>Number of Emails: ';
                emailBodyConfirmMove+=originCase.EmailMessages.size()+'</p><p>Case Subject: ';
                emailBodyConfirmMove+='<a href="'+cssProdOrgURL+targetCase.id+'">'+targetCase.Subject+'</a></p><br/><table ><tr ><th>Subject</th><th>From Name</th><th>From Address</th><th>Message Date</th></tr>';
                
                for(EmailMessage emCloned :oldEmailId2newEmail.values()){
                    emailBodyConfirmMove+='<tr><td><a href="'+cssProdOrgURL+emCloned.id+'">'+emCloned.Subject+'</a></td>';
                    emailBodyConfirmMove+='<td>'+emCloned.FromName+'</td>';
                    emailBodyConfirmMove+='<td>'+emCloned.FromAddress+'</td>';
                    emailBodyConfirmMove+='<td>'+emCloned.MessageDate+'</td></tr>';
                    
                }
                emailBodyConfirmMove+='</table>';
                if(string.valueOf(targetCase.OwnerId).startsWith('005')){//owner is user not queue
                    List<Messaging.SingleEmailMessage> lstMsgs = new List<Messaging.SingleEmailMessage>();
                    Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
                    user targetOwner = [SELECT Id, email FROM user WHERE id=:targetCase.OwnerId AND email != null];
                    msg.setToAddresses(new List<String>{targetOwner.email});
                    msg.setHTMLbody(emailBodyConfirmMove);
                    msg.setSubject('Emails transferred to CASE -'+targetCase.CaseNumber);

                    lstMsgs.add(msg);
                    Messaging.SendEmailResult[] r = Messaging.sendEmail(lstMsgs);
                    
                }
            }
            
            
        } catch(Exception e) {
  system.debug('** EXCEPTION - '+e.getMessage());
            return e.getMessage();
        }
        
        return Label.Success_msg;
    }
  • September 24, 2021
  • Like
  • 0