• Jos Vervoorn
  • NEWBIE
  • 60 Points
  • Member since 2014
  • Salesforce Consultant
  • DPA GEOS

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 19
    Replies
Hi,

I have created a simple Rest API endpoint however my test class is not touching the endpoint at all. The API URL mapping is

//** services/apexrest/accounts/0016E00000YNC49/entitlements
@RestResource(urlMapping='/accounts/*/entitlements')
Global with sharing class U4_REST_AccountEntitlements {
    @HttpGet
    global static Account getAccount(){

and returns entitlement values. Using REST Explorer within workbench it works perfectly but when I run the test class it is not returning any values. In fact ... the result is [REST_AccountEntitlements_TEST].RestResource response:RestResponse:[headers={}, responseBody=null, statusCode=null]​

Any help would be much appreciated.
Test.startTest();

           Id recordId = NewServiceAccount.Id;
           RestRequest request = new RestRequest();
           RestResponse response = new RestResponse();
           request.httpMethod = 'GET';

           Request.requestURI  ='/services/apexrest/accounts/'+NewServiceAccount.Id+'/entitlements';
           System.debug(LoggingLevel.Info,'+*+*+*+*+*+*+* '+NewServiceAccount.id);

           System.debug(LoggingLevel.Info,'[REST_AccountEntitlements_TEST].RestResource response:'+Request.requestURI);

           RestContext.request = request;
           RestContext.response = response;

           System.debug(LoggingLevel.Info,'[REST_AccountEntitlements_TEST].RestResource response:'+response); 
  
        Test.stopTest();

 
HI, I have a 'simple' trigger on the opportunity which creates new contact role entry whenever the Contact__c is changed. So the trigger is Before Update.
 
If(Trigger.IsUpdate){ //** 18/12/2017 - Changed from Insert to Update.. 
        For (Opportunity Opp: Trigger.new){
            if (Trigger.oldMap.get(opp.Contact__c) != null) { //** So we have a contact !!
               Opportunity OldContact = trigger.oldmap.get(Opp.Contact__c);
               If (Opp.Contact__c == OldContact.Id){
                   System.debug('** * ** ||AutoSetOpportunityLookupValues.Trigger - Old Contact....:'+OldContact);
                   System.debug('** * ** ||AutoSetOpportunityLookupValues.Trigger - New Contact....:'+Opp.Contact__c);
               }
            }
        }
So at first in my unit test I create opportunity without contact. All is fine. Then I perform several updates. One of these is to actually update the Contact__c with a value (contact Id) as it's a lookup.
NewQualificationOpportunity.VAT_Included__c = false;
         NewQualificationOpportunity.Contact__c = NewContactII.id;
         NewQualificationOpportunity.StageName='Written Approval';
         Update NewQualificationOpportunity;

However ... 

               Opportunity OldContact = trigger.oldmap.get(Opp.Contact__c);
               If (Opp.Contact__c == OldContact.Id){

are never touched ....

 
Hi,

I'm stuck (real stuck) .. as to working on the following challenge. We have many accounts and each account can have several entitlements. Some even have 20 !. Now, these accounts also have multiple contacts. We have performed import of accounts, contacts and entitlements but now I want to insert all (account) contactId's with all (account) entitlementid's into the entitlementcontact object. Like for example acount Y has 2 contacts and 3 entitlements. This should give 6 rows inside Entitlement contacts. However ... some records are already there as we are onboarding another team 

So I managed to create some code ... however I keep running into the following error: Before Insert or Upsert list must not have two identically equal elements

Below my complete code ... maybe i'm on the wrong trail here but ive tried several other ways. Joining data within Excel is not really within my conform zone. All support is much appreciated.
 
List<Id> contactIds = new List<Id>();
List<Id> EntIds = new List<Id>();
List<EntitlementContact> NewEnTlCont = new List<EntitlementContact>();
List<Account> listAccount = [select id,Name ,(select id, Product__c from Entitlements), (select id, email from contacts) from account where IsService__c = true and id in (Select Accountid from entitlement where Asset.Config_ID__c != null and TierSupportLookup__c = 'a0T25000003e0cX' and status='Active' and Status__c = 'No' and CreatedById='0052X000007vbYw') limit 500];

system.debug(LoggingLevel.Info,'*** Numb of Accounts ' + listAccount.size());

For(Account acc : listAccount)
{
        EntitlementContact newEntCnt = new EntitlementContact();
	List<Contact> lstContact = acc.contacts;
	for(Contact cont :lstContact)
	{
		//System.debug(LoggingLevel.Info,cont.id+'('+cont.email+')');
            //**    contactIds.add(cont.id);

               List<Entitlement> lstEntitlement = acc.Entitlements;
               for(entitlement entl:lstentitlement){
            //      System.debug(LoggingLevel.Info,'*** ContactId:'+Cont.id+', EntitlementId:'+  entl.id);
                  contactIds.add(cont.id);
                  EntIds.add(entl.id);
                 
                    newEntCnt.ContactId = cont.id;
                    newEntCnt.EntitlementId = Entl.id;
                    NewEnTlCont.add(NewEntCnt);
                 
               }
	}
}
system.debug(LoggingLevel.Info,'*** contactIds:' + contactIds.size());
system.debug(LoggingLevel.Info,'*** EntIds:' + EntIds.size());
System.debug(logginglevel.info,'*** NewEnTlCont:'+NewEnTlCont.size());
Insert NewEnTlCont;


 
Hi, I'm running into the famous SOQL Governor limit's when executing Apex batch. One of the reasons is that whenever a case record is updated ... the MileStoneTimeCalculator class is called/executed which has 4 SOQL queries.

Maybe anyone of you can simplify the code and lower the SOQL queries. All help is gratefully appreciated ...
 
Global class U4_Legacy_INC_MilestoneTimeCalculator implements Support.MilestoneTriggerTimeCalculator {

    //** Constructor for this class.
    global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId)
    {  
        Integer MilestoneValue;
        Product_Milestone_Times__c ProductMilestoneSet;
        Milestone_Times__c EntitlementMilestoneSet;

        //** Select values from case
        Case caseRec = [SELECT Id, EntitlementId, ProductId, Priority, Contractual_Type__c FROM Case WHERE Id=:caseId LIMIT 1];
        MilestoneType mtype = [SELECT Name FROM MilestoneType WHERE Id=:milestoneTypeId];

        // Retrieve Milestone definition from Entitlement
        EntitlementMilestoneSet = [SELECT Response_Time__c, Resolution_Time__c, Software_Resolution_Time__c FROM Milestone_Times__c WHERE Entitlement__c =: caseRec.EntitlementId AND Priority__c =: caseRec.Priority];

        // Retrieve Internal Milestone definition from Product
        ProductMilestoneSet = [SELECT Response_Time__c, Resolution_Time__c, Software_Resolution_Time__c FROM Product_Milestone_Times__c WHERE Product__c =: caseRec.ProductId AND Priority__c =: caseRec.Priority];

        if(mtype.Name == SEConstants.FIRSTRESPONSETIME){
            if(caseRec.Contractual_Type__c == SEConstants.INTERNAL_ONLY)
            {
                // Take First Response time from Product
                MilestoneValue = ProductMilestoneSet.Response_Time__c.intValue();
            }
            else
            {
                // Take First Response time from Entitlement
                MilestoneValue = EntitlementMilestoneSet.Response_Time__c.intValue();
            }
        } // Response Time
        
        if(mtype.Name == SEConstants.RESOLUTIONTIME){
            if(caseRec.Contractual_Type__c == SEConstants.INTERNAL_ONLY || caseRec.Contractual_Type__c == SEConstants.FIRST_RESPONSE_ONLY)
            {
                // Take Resolution time from Product
                MilestoneValue = ProductMilestoneSet.Resolution_Time__c.intValue();
            }
            else
            {
                // Take Resolution time from Entitlement
                MilestoneValue = EntitlementMilestoneSet.Resolution_Time__c.intValue();
            }
        } // Resolution Time
            
        if(mtype.Name == SEConstants.SOFTWARERESOLUTIONTIME){
           If(caseRec.Contractual_Type__c == SEConstants.INTERNAL_ONLY || caseRec.Contractual_Type__c == SEConstants.FIRST_RESPONSE_ONLY || caseRec.Contractual_Type__c == SEConstants.FIRST_RESPONSE_RESOLUTION_ONLY || (caseRec.Contractual_Type__c == SEConstants.FIRST_RESPONSE_RESOLUTION_P1_P2_SOFTWARE && (caseRec.Priority == SEConstants.PRIORITY_3 || caseRec.Priority == SEConstants.PRIORITY_4)))
            {
                // Take Software Resolution time from Product
                MilestoneValue = ProductMilestoneSet.Software_Resolution_Time__c.intValue();
            }
            Else
            {
                // Take Software Resolution time from Entitlement
                MilestoneValue = EntitlementMilestoneSet.Software_Resolution_Time__c.intValue();
            }
        } // Software Resolution Time       
        Return MilestoneValue;
    }
}

 
Hi,

We have a batch class running but it's failing because of the records it needs to process. We are running into SOQL query governor limits. So, for the time being, we limited the record selection and changed the frequency. For the short term just fine however while developing a new and improved class, I was wondering if it would be possible to commit all processed records before an exception. This way the records to be processed would not pileup and making sure that only the failing row remains unprocessed.

Like for example if the batch would close all cases which have been waiting for customer feedback for 28 days (or more)  all would be processed except the few cases which have caused an exception.
When I try to compile it get the following error:

Account.Name, ERROR at Row:7: Column:13 Didn't understand relationship 'Account' in field patch. If you are attempting to use a custom relationship .... // // please reference your WSDL or the describe call ..

This refers to the following line ....

               List<User> lstUser = [SELECT 
            Id, 
            ContactId,
            Email,
            Username,
            AccountId, 
            Account.Name, 
            Profile.Name,
            FROM User 
            WHERE Id = :UserInfo.getUserId()];

Using Workbench I can simply use the query and it returns results. I also check field level security on the name field in the account but all profiles have access.Class btw this line is in is still in API v35 .. but I don't think that is causing the issue.
Is there a way that anyone know of to 'bulk' update custom record types. We have made several changes to the case object and we would like to have the pile of report types to include these new fields. I know we should have kept reporting types limited but we have not .. for many reasons...

So we have some work to do .... and I was wondering if there's a way but .... I'm afraid it's not possible ...
is there a way to launch a VF page as modal dialog from using a custom list button. Now I know using a custom javascript (list) button it's doable but how about without  .... 

When I select multiple records and press this button from within the console .. I need these cases to be processed. However .. I would like to have a small dialog to confirm or present an error if occurred.

If not I would have to stick with JS code but ....preferable not.

 
Seeking a way to update case field after milestone processing. We have tried several options like flow with process builder, apex trigger (with/without @Future annotation) but ... whatever we try .... case field is not updated.

To sketch the scenario:
On the case, we would like to have a field to contain the deadline for the active milestone. So when we complete the current milestone ... this custom field get's populated with the deadline.

Now we can do this whenever a field update on the case has been performed ... but it seems that milestone processing takes place after triggers and after process builder. I have seen some samples out there but  ... I'm having a hard time to get this working while it sounds so easy.

 - milestone is completed / case deadline is populated by next milestone

All help & support is much appreciated.

I have created 4 VF pages. 2 for case creation on comm portal (different types) and 2 for internal support agents. As we have come a long way we now also have 4 controller extensions.
  • case type A - Portal
  • case type B - portal
  • case type A - internal
  • case type B - internal
Now all these extensions have lot's of different conditions to retrieve options for creating a case. I know it's not ideal to keep these 4 extensions but given the situation, we have already made huge steps in efficiency and most of all .. eliminate JavaScript. 

However .. we would like to make it more efficient as the final method within these extensions all deal with the actual insert of the case record. We would like to create a separate class providing a single method to actually perform the insert.
//** Mapping of values for case record creation
            objCase.RecordTypeId          = RecType.id;
            objCase.AssetId                     = AssetID;
            objCase.BusinessHoursId     = objCase.Entitlement.BusinessHoursId;

            If (IsMainContactTypeValue == 'Partner'){ 
                objCase.CaseCreatedByPartnerUser__c = true;
            } else {
                objCase.CaseCreatedByPartnerUser__c = false;
            }


            try{
                insert objCase;
            } catch (Exception e){
                System.debug('** ** ** Controller || Creation of Service Request failed  ....');
            }
Now, in general, the mapping of these various case fields for every type of case record is the same. Some have fewer values .. could be explicitly NULL.

Now my question is .. would .. it be easy to create another controller providing a method to actually create the case and prevent repeating the mapping of values in each extension as when we need to add/remove a field .. we need to make sure it's done in all 4 classes. if possible please share the basic idea ...
I'm creating cases thru a community and using VF/Extention to submit to dB. 
AssignmentRule CaR = new AssignmentRule();
      CaR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];

       System.debug('** * ** Controller || Retrieve Case Assignment Rule ...');
     
       Database.DMLOptions dmlOpts = new Database.DMLOptions();
       dmlOpts.assignmentRuleHeader.assignmentRuleId= CaR.id;
            objCase.SetOptions(dmlOpts);
When creating case I get the following error: sObject type ÁssignmentRule'is not supported. 

Now I do notice that when I remove with charing from my controller extension it works but that would mean all sharing rules are ineffective which is not really helping. I also would like to stay away from doing this in after update trigger as some case need to run thru assignment rules and some don't so I need to include the login there. 

Is there another way .. like for example a method inside a utility class ... some samples would be great. Many thanks in advance.


 
I have a method created to handle the creation of a case and many other DML activities.
public PageReference SaveAndAssignIncToMe() String rValue; rValue = PullSelectAssignCase.AddCaseTeamMember(ObjCase.id, System.UserInfo.getUserId(), SEConstants.CASEOWN, SEConstants.USER); if(rValue == SEConstants.RETURN_TRUE){ //** So it was ok } else { //** So it was not ok ... }
The method is inside another (global) extention class ...
public static String AddCaseTeamMember(Case c, User u , String mRole, String tUser) { Database.SaveResult caseUpdateResult; String rValue; ///// ///// return rValue; } // End of AddCaseTeamMember
When I call the method from another VF page ... there's no issue ... it's been bugging me for some time now but I can't figure out what is wrong here...
 
Hi there. Struggling with the limits of SOQL .... if looking for a way to retrieve the most recent case for all accounts. In SQL such would be very simple ...

SELECT ID FROM Case U1
WHERE CreatedDate = (SELECT MAX(CreatedDate) FROM Case WHERE AccountID= U1.AccountID)

But SOQL does not allow me to due to the bind variable. Would anyone be able to support ?
Seeking a way to update case field after milestone processing. We have tried several options like flow with process builder, apex trigger (with/without @Future annotation) but ... whatever we try .... case field is not updated.

To sketch the scenario:
On the case, we would like to have a field to contain the deadline for the active milestone. So when we complete the current milestone ... this custom field get's populated with the deadline.

Now we can do this whenever a field update on the case has been performed ... but it seems that milestone processing takes place after triggers and after process builder. I have seen some samples out there but  ... I'm having a hard time to get this working while it sounds so easy.

 - milestone is completed / case deadline is populated by next milestone

All help & support is much appreciated.
Hi,

I have created a simple Rest API endpoint however my test class is not touching the endpoint at all. The API URL mapping is

//** services/apexrest/accounts/0016E00000YNC49/entitlements
@RestResource(urlMapping='/accounts/*/entitlements')
Global with sharing class U4_REST_AccountEntitlements {
    @HttpGet
    global static Account getAccount(){

and returns entitlement values. Using REST Explorer within workbench it works perfectly but when I run the test class it is not returning any values. In fact ... the result is [REST_AccountEntitlements_TEST].RestResource response:RestResponse:[headers={}, responseBody=null, statusCode=null]​

Any help would be much appreciated.
Test.startTest();

           Id recordId = NewServiceAccount.Id;
           RestRequest request = new RestRequest();
           RestResponse response = new RestResponse();
           request.httpMethod = 'GET';

           Request.requestURI  ='/services/apexrest/accounts/'+NewServiceAccount.Id+'/entitlements';
           System.debug(LoggingLevel.Info,'+*+*+*+*+*+*+* '+NewServiceAccount.id);

           System.debug(LoggingLevel.Info,'[REST_AccountEntitlements_TEST].RestResource response:'+Request.requestURI);

           RestContext.request = request;
           RestContext.response = response;

           System.debug(LoggingLevel.Info,'[REST_AccountEntitlements_TEST].RestResource response:'+response); 
  
        Test.stopTest();

 
HI, I have a 'simple' trigger on the opportunity which creates new contact role entry whenever the Contact__c is changed. So the trigger is Before Update.
 
If(Trigger.IsUpdate){ //** 18/12/2017 - Changed from Insert to Update.. 
        For (Opportunity Opp: Trigger.new){
            if (Trigger.oldMap.get(opp.Contact__c) != null) { //** So we have a contact !!
               Opportunity OldContact = trigger.oldmap.get(Opp.Contact__c);
               If (Opp.Contact__c == OldContact.Id){
                   System.debug('** * ** ||AutoSetOpportunityLookupValues.Trigger - Old Contact....:'+OldContact);
                   System.debug('** * ** ||AutoSetOpportunityLookupValues.Trigger - New Contact....:'+Opp.Contact__c);
               }
            }
        }
So at first in my unit test I create opportunity without contact. All is fine. Then I perform several updates. One of these is to actually update the Contact__c with a value (contact Id) as it's a lookup.
NewQualificationOpportunity.VAT_Included__c = false;
         NewQualificationOpportunity.Contact__c = NewContactII.id;
         NewQualificationOpportunity.StageName='Written Approval';
         Update NewQualificationOpportunity;

However ... 

               Opportunity OldContact = trigger.oldmap.get(Opp.Contact__c);
               If (Opp.Contact__c == OldContact.Id){

are never touched ....

 
Hi,

I'm stuck (real stuck) .. as to working on the following challenge. We have many accounts and each account can have several entitlements. Some even have 20 !. Now, these accounts also have multiple contacts. We have performed import of accounts, contacts and entitlements but now I want to insert all (account) contactId's with all (account) entitlementid's into the entitlementcontact object. Like for example acount Y has 2 contacts and 3 entitlements. This should give 6 rows inside Entitlement contacts. However ... some records are already there as we are onboarding another team 

So I managed to create some code ... however I keep running into the following error: Before Insert or Upsert list must not have two identically equal elements

Below my complete code ... maybe i'm on the wrong trail here but ive tried several other ways. Joining data within Excel is not really within my conform zone. All support is much appreciated.
 
List<Id> contactIds = new List<Id>();
List<Id> EntIds = new List<Id>();
List<EntitlementContact> NewEnTlCont = new List<EntitlementContact>();
List<Account> listAccount = [select id,Name ,(select id, Product__c from Entitlements), (select id, email from contacts) from account where IsService__c = true and id in (Select Accountid from entitlement where Asset.Config_ID__c != null and TierSupportLookup__c = 'a0T25000003e0cX' and status='Active' and Status__c = 'No' and CreatedById='0052X000007vbYw') limit 500];

system.debug(LoggingLevel.Info,'*** Numb of Accounts ' + listAccount.size());

For(Account acc : listAccount)
{
        EntitlementContact newEntCnt = new EntitlementContact();
	List<Contact> lstContact = acc.contacts;
	for(Contact cont :lstContact)
	{
		//System.debug(LoggingLevel.Info,cont.id+'('+cont.email+')');
            //**    contactIds.add(cont.id);

               List<Entitlement> lstEntitlement = acc.Entitlements;
               for(entitlement entl:lstentitlement){
            //      System.debug(LoggingLevel.Info,'*** ContactId:'+Cont.id+', EntitlementId:'+  entl.id);
                  contactIds.add(cont.id);
                  EntIds.add(entl.id);
                 
                    newEntCnt.ContactId = cont.id;
                    newEntCnt.EntitlementId = Entl.id;
                    NewEnTlCont.add(NewEntCnt);
                 
               }
	}
}
system.debug(LoggingLevel.Info,'*** contactIds:' + contactIds.size());
system.debug(LoggingLevel.Info,'*** EntIds:' + EntIds.size());
System.debug(logginglevel.info,'*** NewEnTlCont:'+NewEnTlCont.size());
Insert NewEnTlCont;


 
When I try to compile it get the following error:

Account.Name, ERROR at Row:7: Column:13 Didn't understand relationship 'Account' in field patch. If you are attempting to use a custom relationship .... // // please reference your WSDL or the describe call ..

This refers to the following line ....

               List<User> lstUser = [SELECT 
            Id, 
            ContactId,
            Email,
            Username,
            AccountId, 
            Account.Name, 
            Profile.Name,
            FROM User 
            WHERE Id = :UserInfo.getUserId()];

Using Workbench I can simply use the query and it returns results. I also check field level security on the name field in the account but all profiles have access.Class btw this line is in is still in API v35 .. but I don't think that is causing the issue.

I have created 4 VF pages. 2 for case creation on comm portal (different types) and 2 for internal support agents. As we have come a long way we now also have 4 controller extensions.
  • case type A - Portal
  • case type B - portal
  • case type A - internal
  • case type B - internal
Now all these extensions have lot's of different conditions to retrieve options for creating a case. I know it's not ideal to keep these 4 extensions but given the situation, we have already made huge steps in efficiency and most of all .. eliminate JavaScript. 

However .. we would like to make it more efficient as the final method within these extensions all deal with the actual insert of the case record. We would like to create a separate class providing a single method to actually perform the insert.
//** Mapping of values for case record creation
            objCase.RecordTypeId          = RecType.id;
            objCase.AssetId                     = AssetID;
            objCase.BusinessHoursId     = objCase.Entitlement.BusinessHoursId;

            If (IsMainContactTypeValue == 'Partner'){ 
                objCase.CaseCreatedByPartnerUser__c = true;
            } else {
                objCase.CaseCreatedByPartnerUser__c = false;
            }


            try{
                insert objCase;
            } catch (Exception e){
                System.debug('** ** ** Controller || Creation of Service Request failed  ....');
            }
Now, in general, the mapping of these various case fields for every type of case record is the same. Some have fewer values .. could be explicitly NULL.

Now my question is .. would .. it be easy to create another controller providing a method to actually create the case and prevent repeating the mapping of values in each extension as when we need to add/remove a field .. we need to make sure it's done in all 4 classes. if possible please share the basic idea ...
I'm creating cases thru a community and using VF/Extention to submit to dB. 
AssignmentRule CaR = new AssignmentRule();
      CaR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];

       System.debug('** * ** Controller || Retrieve Case Assignment Rule ...');
     
       Database.DMLOptions dmlOpts = new Database.DMLOptions();
       dmlOpts.assignmentRuleHeader.assignmentRuleId= CaR.id;
            objCase.SetOptions(dmlOpts);
When creating case I get the following error: sObject type ÁssignmentRule'is not supported. 

Now I do notice that when I remove with charing from my controller extension it works but that would mean all sharing rules are ineffective which is not really helping. I also would like to stay away from doing this in after update trigger as some case need to run thru assignment rules and some don't so I need to include the login there. 

Is there another way .. like for example a method inside a utility class ... some samples would be great. Many thanks in advance.


 
I have a method created to handle the creation of a case and many other DML activities.
public PageReference SaveAndAssignIncToMe() String rValue; rValue = PullSelectAssignCase.AddCaseTeamMember(ObjCase.id, System.UserInfo.getUserId(), SEConstants.CASEOWN, SEConstants.USER); if(rValue == SEConstants.RETURN_TRUE){ //** So it was ok } else { //** So it was not ok ... }
The method is inside another (global) extention class ...
public static String AddCaseTeamMember(Case c, User u , String mRole, String tUser) { Database.SaveResult caseUpdateResult; String rValue; ///// ///// return rValue; } // End of AddCaseTeamMember
When I call the method from another VF page ... there's no issue ... it's been bugging me for some time now but I can't figure out what is wrong here...
 
Hi there. Struggling with the limits of SOQL .... if looking for a way to retrieve the most recent case for all accounts. In SQL such would be very simple ...

SELECT ID FROM Case U1
WHERE CreatedDate = (SELECT MAX(CreatedDate) FROM Case WHERE AccountID= U1.AccountID)

But SOQL does not allow me to due to the bind variable. Would anyone be able to support ?