• Jagadeesh M
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 2
    Replies
Hi All, Unable to complete the test class as im getting the error "Rest API FATAL_ERROR System.QueryException: List has no rows for assignment to SObject In Test Class"

My Apex Class:

@RestResource(urlMapping='/GetContactId/*')
global without sharing class PersonContactRestEndpoint{
   
   @HttpGet
    global static string getPersonContactId() {
        RestRequest request = RestContext.request;
        
        // grab the EmailId & Brand from the end of the URL       
        String EmailId= RestContext.request.params.get('emailId');
        String Brand= RestContext.request.params.get('brand');
         
        system.debug('EmailId==>'+emailId);      
        system.debug('Brand==>'+brand);
        
        Account CustomerId=  [SELECT PersonContactId FROM Account WHERE CC_Brand__c = :Brand AND PersonEmail = :EmailId LIMIT 1];
        String PersonContactId = CustomerId.PersonContactId;
        
        system.debug('PersonContactId==>'+PersonContactId);
        return PersonContactId;          
    }
}

Test Class:

@IsTest
private class PersonContactRestEndpointTest
{
    static testMethod void testGetMethod()
    {
        Account acc = new Account();
        acc.Name='Test';
        acc.AccountNumber ='12345';
        insert acc;
        
      // Create Required data here  
    
        Test.startTest();
        RestResponse res = new RestResponse();
        RestRequest req = new RestRequest(); 
        
        req.params.put('PersonEmail', 'sschimpf@urbn.com');
        req.params.put('CC_Brand__c', 'Anthropologie');  // ==> CC_Brand__c is formula field
        req.params.put('PersonContactId', '0032h00000GfE6rAAF');
        
         req.httpMethod = 'Get';
         req.addHeader('Content-Type', 'application/json'); // Add a JSON Header as it is validated 
        // req.requestURI= URL.getOrgDomainUrl() +'/services/apexrest/GetContactId?brand=Anthropologie&emailId=sschimpf@urbn.com';
         //req.requestURI= URL.getOrgDomainUrl() +'/services/apexrest/GetContactId';
         req.requestURI= '/services/apexrest/GetContactId';
         RestContext.request = req;
         RestContext.response = res;
         string results = PersonContactRestEndpoint.getPersonContactId(); 
        Test.stopTest();
        
    }
}

Could you some one help me on this? Thanks in advance for the help..

Thanks..!!!
 
private static void DuplicateAccountMerge(List<Account> triggerNew) {
        try{
        // Merges a new Account with an existing Account based on matching email addresses.
        // Old Account is the Master Account- New Account information will be added to the Master Account only where the Master Account information is blank
       
        // Set up variables
        List<Id> triggerId = new List<Id>();
        List<String> triggerEmail = new List<String>();
       
        // Read trigger into variable(s)
        for (Account acc : Triggernew)
            {
                triggerId.add(acc.Id);
                triggerEmail.add(acc.PersonEmail);            
            }
     
        // Get all Account fields formatted for use in a SOQL query
        Map<String, Schema.SObjectField> AllLeadFields = Schema.getGlobalDescribe().get('Account').getDescribe().SObjectType.getDescribe().fields.getMap();
     
         List<String> accessiblefields = new List<String>();
     
          for(Schema.SObjectField field : AllLeadFields.values()){
                if(field.getDescribe().isAccessible())
                    accessiblefields.add(field.getDescribe().getName());
            }
     
            String allfields='';
           
            for(String fieldname : accessiblefields)
                allfields += fieldname+',';
     
            allfields = allfields.subString(0,allfields.length()-1);
            
            
           //Query string to get all Accounts with the same email address
           
            String masterSOQLQuery = 'SELECT ' + allfields + ' FROM Account WHERE PersonEmail IN:  triggerEmail ORDER BY CreatedDate';
     
             
            // Query string to get all Accounts with the same email address excluding the Master Account
            String duplicatesSOQLQuery = 'SELECT ' + allfields + ' FROM Account WHERE PersonEmail IN: triggerEmail AND Id != :masterAccountID LIMIT 2';
     
            List<Account> matchingAccounts = database.query(masterSOQLQuery);
     
            Account masterAccount = matchingAccounts[0];
            Id masterAccountID = masterAccount.Id;
       
            List<Account> duplicateAccounts = database.query(duplicatesSOQLQuery);
           
            // Go through the master and duplicate record fields, and update the master record where its fields are blank, 
            //but the duplicate's is populated
            
            SObjectType AccountType = Schema.getGlobalDescribe().get('Account');
            Map<String, Schema.sObjectField> mapFields = AccountType.getDescribe().fields.getMap();
       
               for(String fieldName : mapFields.keySet())
                    {
                        if(masterAccount.get(fieldName) == null && duplicateAccounts[0].get(fieldName) != null)
                            {
                                masterAccount.put(fieldName, duplicateAccounts[0].get(fieldName));
                            }
                    } 
               
                    if(masterAccount != null) {
                        //merge masterAccount duplicateAccounts;  
                        Database.MergeResult[] results = Database.merge(masterAccount, duplicateAccounts, false);
                    }
               }
               Catch(Exception e){
                        system.debug('Exception ***'+e.getMessage());
                        System.debug('Exception_Line_No:' + e.getLineNumber());
                 } 
     }

Thanks in advance...!!
Jagadeesh M
Hi All,
I have trigger and handler class and trying to implement the merge operation. I'm getting the error as "Merge failed. First exception on row 0 with id 0012h00000UXvezAAD; first error: ENTITY_IS_DELETED, entity is deleted: " 
when I try to merge the account if I change the email id on account from UI.

My Trigger Code:

trigger AccountTrigger on Account (before insert, after insert, after update, before update)
{
if (Trigger.isAfter) { if (Trigger.isUpdate) { AccountTriggerFacade.onAfterUpdate(Trigger.new);
}
}
}

Apex Class Code:
-------------------------
public static void onAfterUpdate(List<Account> triggerNew)
{
DuplicateAccountMerge(triggerNew); system.debug('****************DuplicateAccountMerge');
}

private static void DuplicateAccountMerge(List<Account> triggerNew) {
Set<String> emails = new Set<String>();
Map<String, Account> masters = new Map<String, Account>(); system.debug('****************DuplicateAccountMerge1'); for(Account acc : triggernew){ emails.add(acc.PersonEmail); } emails.remove(null); for(Account acc: [SELECT PersonEmail FROM Account WHERE PersonEmail = :emails AND Id NOT IN :Trigger.new])
{
masters.put(acc.PersonEmail, acc);
}
for(Account acc: Triggernew)
{
Account master = masters.get(acc.PersonEmail); if(master != null)
{
merge master acc;
}
}
}
 
Hi, I want to redefine and remove nested for loop and fix couple of issues with below code,

My Method:
------------
public void buildQueueInfo(List<Group> queues, Map<Id, List<GroupMember>> queueIdToMembersMap, List<User> allUsers, Map<Id, User> userMap) {

        for (Group queue : queues) {
            List<GroupMember> gmList = new List<GroupMember>();
            gmList = queueIdToMembersMap.get(queue.Id);
            List<User> nonUsers = new List<User>();

            for (User u : allUsers) {
                Boolean notAMember = true;
                if (gmList != null) {
                    for (GroupMember gm : gmList) {
                        if (u.Id == gm.UserOrGroupId) {
                            notAMember = false;
                        }
                    }
                }
                if (notAMember) {
                    nonUsers.add(u);
                }
            }

            populateQueueInfo(queue, gmList, nonUsers, userMap);
            //To Reduce heap size
            queues=null;
            //allUsers=null;
            gmList=null;
        }
        
    }


your help in this regrads would be greatly appreciates.

Thanks!!
Jagadeesh. M
Hi All,
I have a validation rule on email message object to throw the user friendly error message " please select the disposition value before send a email to the customer ",when case object disposition custom field (pick list) value is null before send a email to customer (see below screenshot for more info).

Error Screen Shot.Is there anyway that we can do resolve this issue in lightning?

Thanks
Jagadeesh.
Hi All,

What does the "Anchor button" on the email compose screen do (see attached screenshot more info). I'm unable to find much more information about anchor button but i do have little more information see below link and that link not helped me.
https://help.salesforce.com/articleView?id=knowledge_create_anchors.htm&type=5 (http://URL)
what exactly achor button will do.

thanks alot in advance.
What does the anchor button on the email compose screen do 
Hi All,
 
I have developed Visual force email template and its working as expected with Process Builder. But the client requirement is changed, they are asking the same template to be used in the Lightning with preview option before sending the email (see the screenshots 1 & 2 below).
 
I’m unable to Send and Preview, When I tried to add the visual force email template In the lightning activities “Email tab”. Is there any way I have to do to enable this preview option and send the Visual force email template or Do I need to do some customization to implement the above requirement.
 
Can any on help me to guide on how to proceed ?

Screenshot# 1:

Screenshot 1

Screenshot#2:

Screenshot 2


Thanks,
Jagadeesh M
Hi, I want to redefine and remove nested for loop and fix couple of issues with below code,

My Method:
------------
public void buildQueueInfo(List<Group> queues, Map<Id, List<GroupMember>> queueIdToMembersMap, List<User> allUsers, Map<Id, User> userMap) {

        for (Group queue : queues) {
            List<GroupMember> gmList = new List<GroupMember>();
            gmList = queueIdToMembersMap.get(queue.Id);
            List<User> nonUsers = new List<User>();

            for (User u : allUsers) {
                Boolean notAMember = true;
                if (gmList != null) {
                    for (GroupMember gm : gmList) {
                        if (u.Id == gm.UserOrGroupId) {
                            notAMember = false;
                        }
                    }
                }
                if (notAMember) {
                    nonUsers.add(u);
                }
            }

            populateQueueInfo(queue, gmList, nonUsers, userMap);
            //To Reduce heap size
            queues=null;
            //allUsers=null;
            gmList=null;
        }
        
    }


your help in this regrads would be greatly appreciates.

Thanks!!
Jagadeesh. M