• Peter Cowen
  • NEWBIE
  • 145 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 65
    Questions
  • 29
    Replies
I am looking into the possibilty of creating a flow that will remove a part of a string inside a variable or field but I am unsure how to do it. 

I currently have a flow that updates a text field with 'hello' on the service contract when a record in another object is created. It also adds 'hello' to the end of the field if it is already populated. 

I would like to introduce a flow that will check whether the record is marked as closed where it will then remove 'hello' and replace with 'bye'. 

I would also like it to remove the 'hello' if the status of the record is marked as retained. 

How would I go about doing it? I would prefer not to add any additional fields
I am developing a visualforce page where I would like to increase a number field by a set amount when the form is saved. 

The field is Time_Spent__c. 

Alternatively we would like something that could get the time a ticket was picked up by an agent and the time when they marked it waiting customer response or closed then and work out the difference and then increase this field. 
I have created a class that links a case with the case comment for a visualforce page but for the life of me I cannot remember how I write a test class for the apex class.

The class I require tests for is:

public class Caselinktocomment
{
    public CaseComment comment { get; set; }
    public String commentText {get; set;}
    public String PublicPrivateAction {get; set;}


    public Caselinktocomment(ApexPages.StandardController stdController) 
    {
        this.comment = new CaseComment(ParentId = stdController.getId());
    }

    public PageReference saveComment()
    {
        insert comment;
        return null;
    }
}

The test Class I have written is:
@istest

Private class Caselinktocommenttests {
    

    static testmethod void createtestdata() {
    Id RecordId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('Service_Desk').getRecordTypeId();
        Case tcase = new Case();
        tCase.Status = 'New';
        tCase.Description = 'This ticket has been created as a test';
        tCase.Subject = 'Test Case';
        tCase.RecordTypeId = RecordId;
        tCase.Reason = 'Access Requests';
        tCase.Origin = '';Phone
        
        INSERT tCase;
        
        CaseComment tComment = new CaseComment();
        tComment.ParentId = tCase.Id;
        tComment.CommentBody = 'Test Comment';
        tComment.IsPublished = FALSE;
        tComment.IsNotificationSelected= FALSE;
        Test.startTest();
        INSERT tComment;
        Test.stopTest();
        system.assertEquals(1, [SELECT count() From CaseComment], 'Test Comment');
        }   
}

The code coverage does not seem to increase. Can anyone advise where I have gone wrong. 
I have created a visualforce page to allow our first line support team to escalate to the 2nd line team. 

When a ticket is escalated we require them to record the time spent on the ticket and have a custom field called time spent and it is set as a number. 

Is there a way to add a field onto the visualforce page that isn't a field on the case but when they enter the time spent it increases the value in the field time spent? 

I have had a look and I cannot seem to find a way to do it
I am currently trying to create a buton on the ticket that will allow a level 1 support engineer to place a ticket in the level 2 queue. 

I have a vf page that contains several fields on case that they need to complete and the case comment.

I have created a extension for the case comment which is:
public class Caselinktocomment
{
    public CaseComment comment { get; set; }

    public Caselinktocomment(ApexPages.StandardController stdController) 
    {
        this.comment = new CaseComment(ParentId = stdController.getId());
    }

    public PageReference saveComment()
    {
        insert comment;
        return null;
    }
}
my visualforce page is:
<apex:page standardController="Case" extensions="Caselinktocomment" >
<script>
var returnurl;
window.onload = function(){
    returnURL = gup('retURL');
    alert('set retURL = ' + returnURL);
    };
    
    function gup(name) { //this function just grabs http params by name
    
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
    var regex5 = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS ); 
    var results = regex.exec( window.location.href );
    if( results == null )    return ""; 
    else    return results[1];}
    
    function redirectBack(){
//alert('Sending you back to ' + returnURL);
window.location.href = '/' + returnURL;
}

</script>
    
    <apex:form >
    <apex:actionFunction name="saveActionFunc" action="{!Save}" oncomplete="redirectBack()" rerender="theBlock" />
        <apex:pageblock title="2nd Line Escalation" >
            <apex:pageBlockSection >
                <apex:inputField value="{!Case.troubleshooting_completed__c}" required="true" />
             </apex:pageBlockSection>   
             <apex:pageBlockSection rendered="true" >
                <apex:inputCheckbox value="{!Case.X2nd_Line_Support__c}" selected="true" />
                </apex:pageBlockSection>
                <apex:pageBlockSection >
                <apex:inputField value="{!Case.Reason_for_Escalation__c}" required="true" />
                </apex:pageBlockSection>
                <apex:pageBlockSection >
                <apex:inputTextarea value="{!Case.further_information__c}" cols="60" rows="10" />
            </apex:pageBlockSection>            
            <apex:pageBlockSection rendered="true">
                <apex:inputTextarea value="{!Comment.CommentBody}"/>                
            </apex:pageBlockSection>
            
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="save" onClick="saveActionFunc();" />
                <apex:commandButton action="{!cancel}" value="cancel" onClick="saveActionFunc();" />
                <apex:commandButton action="{!saveComment}" value="Save Comment"/>
            </apex:pageBlockButtons>
        </apex:pageblock>
            
            
    </apex:form>
    
    
 </apex:page>
I have noticed that when I press Save comment it saves what is set in the field "Reason_for_Escalation__c" and when it is updated the comment is also updated. 

Ideally I would like to just have one save button that will add the comment and update the case fields.

I am unable to see why the save comment button is saving the wrong field and allowing the comment to be updated if the picklist is updated. If you know a way to set the vf save button to save all fields in one that would be great.

Any assistance would be appreciated. My knowledge isn't 100% with apex code. 
Is it possible to create a trigger that can set the priority and the reason for the case based on key words. It would also be good to have the ability to add,remove or update key words without the need to update the trigger?
is it possible to create a visualforce page that when pressing new it displays the record types as images which once pressed navigates to another visualforce page. If so how can this be done?
I have started looking into a way of creating a save to calendar link on a html email template as we find attempting to convert a HTML email template to a visualforce email template. 

I have got the link to appear on the email but I cannot get it to save as a ics file to see if it has worked. The script is below
<script> 
var cal = ics(); 
cal.addEvent('{!Service_Request__c.Name}', '{!Service_Request__c.Change_Details__c}', 'None', '{!Service_Request__c.Expected_Start__c}', '{!Service_Request__c.Expected_Completion_Date__c}'

</script>
<a href="javascript:addToOutlook()">Demo</a>

Is there anything I am missing? 
Is it possible to create a email template that references two different records (for example 2 cases for the same thing). 

We currently create 2 change requests in a custom object for the same task over 2 days but we would like to automate an email that references fields from both change requests before sending out
Is there away of creating an option in cases to calculate the time spent on a ticket. It also would need to pause time option. Could this be done by visual force and if so how could this be done. 
Is there a way of cloning the opportunity progress bar on cases? I would like to display the Case Cycle on the ticket to track where we are. 

The progress will depend on :
Creation - Owner (Queue) and Record Type = X
Investigation - Status and Record Type = X
Resolution - Status and Record Type = X
Closed - Status and Record Type = X

Or is there an option in Lightening that will do this? 
I wonder if anyone is able to assist.

I am trying to do a formula to display a number depending on a certain number of fields. 

The fields are:
(Parent.RecordType.DeveloperName = ServiceDesk
UseRole.Name = Service Desk
Casecomment.IsPublished = True 

Then if all these fields match display 1 else 0 

Or I would like it to display the number 1 if comment is from one of the servicedesk team and is public 
Is there a way of having a count of the number of public comments that are on a case either by using a trigger or workflow.
I wonder if you can help.

I have created a flow with 2 variables CaseID and IncidentID
In the button URL I have added the CaseID so it will allocate to the caseID variable
and when the Incident is created it puts the recordID into the IncidentID variable
I then do an update on the case to set the IncidentID variable into the lookup field but it is not updating that field. Any Ideas?
I have created a visualforce page and allocated a custom object to it then assigned it to a tab. The fields appear but the contents don't. Does the visualforce page need to be allocated the custom object? 
I have created a process using the processor builder with the below criteria
If record type is X
and field X is false submit for approval
else
If record type is X
and field X is true submit for approval (different approval process)

The first criteria works but when setting field x to true i get (On creation)
This record is currently in an approval process. A record can be in only one approval process at a time.
Is it possible to enable lightning for a record type on a custom object? if so how is it done?
I have had a few instances where i recieve the following error:

UpdateServiceContract: execution of AfterUpdate
 
caused by: System.FinalException: Record is read-only

Trigger.UpdateServiceContract: line 8, column 1

Is there a way of setting the trigger to check if the field is read only and if it is make it writeable before applying the update?

The trigger is :

trigger UpdateServiceContract on Case (before insert,before update,after update) {
Id caseRecordTypeId = [Select id from RecordType where sObjectType = 'Case' and developerName ='Service_Desk' ].id ;
for (Case c : trigger.new) {
if (c.RecordTypeID == caseRecordTypeId )
if (c.service_contract__c == NULL){
try{
//c.Service_Contract__c = [select Id from ServiceContract where AccountId ='810D0000000Cfza' and Primary_Service_Contract__c = True].id;
c.Service_Contract__c = [select Id from ServiceContract where AccountId = :c.AccountId and Primary_Service_Contract__c = True limit 1].id;
}catch(QueryException e) {
//No records found. Maybe you should set it to Null
}
}
}
}
A strange question. Is there a way I could create a status page using an record type on a custom object.

background :
we have a custom object we use to raise any issues we encounter like for instance a server goes down. It would be great if we could build some sort of status page where it lists the different areas like servers phones emails and depending on the priority and count it displays a traffic light system. 

Is this his possible and if so where would you start?

We have an issue where we are attempting to use SSO but it is erroring in Salesforce. The Certifcates have not expired. Our ADFS Server is functioning successfully and it is sending the SAML without an issue.

When checking the logs we see
Signature or certificate problems
  The signature in the assertion is not valid
  Is the correct certificate supplied in the keyinfo? false

Has anyone come across this before?

 

I have a trigger that uses the account name to populate the service contract on the case. I have come across a few instances where we need to change the contact and account on the case so we delete the following off the case:
1. Service Contract
2. Account
3. Contact (then add a new contact)
Once I press save it errors with caused an unexpected exception, contact your administrator: Trigger: execution of AfterUpdate caused by: System.FinalException:Record is read-only: Trigger. Trigger line 9,column 1

The trigger is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
trigger UpdateServiceContract on Case (before insert,before update, after update) {
  Id caseRecordTypeId = [Select id from RecordType where sObjectType = 'Case' and developerName ='Service_Desk' ].id ; 
    for (Case c : trigger.new) {
    if (c.RecordTypeID == caseRecordTypeId )
      if (c.service_contract__c == NULL){
        try{
          //c.Service_Contract__c = [select Id from ServiceContract where AccountId ='810D0000000Cfza' and Primary_Service_Contract__c = True].id;
        c.Service_Contract__c = [select Id from ServiceContract where AccountId = :c.AccountId and Primary_Service_Contract__c = True limit 1].id;
        }catch(QueryException e) {
          //No records found. Maybe you should set it to Null
      }
     }
    }
  
}

How do I amend the trigger to accomadate for the deletion of an account and service contract and a new contact is added?
I am wondering if anyone has created an area like ticket comments that will allow you to fill in if you call a customer relating to a case.

All I would like it to do is either a button you press called "Called Customer" and it displays a window where you enter person name - list of the call contents and it adds it to a phone call area or something. This will help us get a better case history, I.E. How many phone calls made - by who - what was mentioned in the phone call
I have created a class that links a case with the case comment for a visualforce page but for the life of me I cannot remember how I write a test class for the apex class.

The class I require tests for is:

public class Caselinktocomment
{
    public CaseComment comment { get; set; }
    public String commentText {get; set;}
    public String PublicPrivateAction {get; set;}


    public Caselinktocomment(ApexPages.StandardController stdController) 
    {
        this.comment = new CaseComment(ParentId = stdController.getId());
    }

    public PageReference saveComment()
    {
        insert comment;
        return null;
    }
}

The test Class I have written is:
@istest

Private class Caselinktocommenttests {
    

    static testmethod void createtestdata() {
    Id RecordId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('Service_Desk').getRecordTypeId();
        Case tcase = new Case();
        tCase.Status = 'New';
        tCase.Description = 'This ticket has been created as a test';
        tCase.Subject = 'Test Case';
        tCase.RecordTypeId = RecordId;
        tCase.Reason = 'Access Requests';
        tCase.Origin = '';Phone
        
        INSERT tCase;
        
        CaseComment tComment = new CaseComment();
        tComment.ParentId = tCase.Id;
        tComment.CommentBody = 'Test Comment';
        tComment.IsPublished = FALSE;
        tComment.IsNotificationSelected= FALSE;
        Test.startTest();
        INSERT tComment;
        Test.stopTest();
        system.assertEquals(1, [SELECT count() From CaseComment], 'Test Comment');
        }   
}

The code coverage does not seem to increase. Can anyone advise where I have gone wrong. 
I have created a visualforce page to allow our first line support team to escalate to the 2nd line team. 

When a ticket is escalated we require them to record the time spent on the ticket and have a custom field called time spent and it is set as a number. 

Is there a way to add a field onto the visualforce page that isn't a field on the case but when they enter the time spent it increases the value in the field time spent? 

I have had a look and I cannot seem to find a way to do it
I am currently trying to create a buton on the ticket that will allow a level 1 support engineer to place a ticket in the level 2 queue. 

I have a vf page that contains several fields on case that they need to complete and the case comment.

I have created a extension for the case comment which is:
public class Caselinktocomment
{
    public CaseComment comment { get; set; }

    public Caselinktocomment(ApexPages.StandardController stdController) 
    {
        this.comment = new CaseComment(ParentId = stdController.getId());
    }

    public PageReference saveComment()
    {
        insert comment;
        return null;
    }
}
my visualforce page is:
<apex:page standardController="Case" extensions="Caselinktocomment" >
<script>
var returnurl;
window.onload = function(){
    returnURL = gup('retURL');
    alert('set retURL = ' + returnURL);
    };
    
    function gup(name) { //this function just grabs http params by name
    
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
    var regex5 = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS ); 
    var results = regex.exec( window.location.href );
    if( results == null )    return ""; 
    else    return results[1];}
    
    function redirectBack(){
//alert('Sending you back to ' + returnURL);
window.location.href = '/' + returnURL;
}

</script>
    
    <apex:form >
    <apex:actionFunction name="saveActionFunc" action="{!Save}" oncomplete="redirectBack()" rerender="theBlock" />
        <apex:pageblock title="2nd Line Escalation" >
            <apex:pageBlockSection >
                <apex:inputField value="{!Case.troubleshooting_completed__c}" required="true" />
             </apex:pageBlockSection>   
             <apex:pageBlockSection rendered="true" >
                <apex:inputCheckbox value="{!Case.X2nd_Line_Support__c}" selected="true" />
                </apex:pageBlockSection>
                <apex:pageBlockSection >
                <apex:inputField value="{!Case.Reason_for_Escalation__c}" required="true" />
                </apex:pageBlockSection>
                <apex:pageBlockSection >
                <apex:inputTextarea value="{!Case.further_information__c}" cols="60" rows="10" />
            </apex:pageBlockSection>            
            <apex:pageBlockSection rendered="true">
                <apex:inputTextarea value="{!Comment.CommentBody}"/>                
            </apex:pageBlockSection>
            
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="save" onClick="saveActionFunc();" />
                <apex:commandButton action="{!cancel}" value="cancel" onClick="saveActionFunc();" />
                <apex:commandButton action="{!saveComment}" value="Save Comment"/>
            </apex:pageBlockButtons>
        </apex:pageblock>
            
            
    </apex:form>
    
    
 </apex:page>
I have noticed that when I press Save comment it saves what is set in the field "Reason_for_Escalation__c" and when it is updated the comment is also updated. 

Ideally I would like to just have one save button that will add the comment and update the case fields.

I am unable to see why the save comment button is saving the wrong field and allowing the comment to be updated if the picklist is updated. If you know a way to set the vf save button to save all fields in one that would be great.

Any assistance would be appreciated. My knowledge isn't 100% with apex code. 
Is it possible to create a trigger that can set the priority and the reason for the case based on key words. It would also be good to have the ability to add,remove or update key words without the need to update the trigger?
Is there a way of having a count of the number of public comments that are on a case either by using a trigger or workflow.
I wonder if you can help.

I have created a flow with 2 variables CaseID and IncidentID
In the button URL I have added the CaseID so it will allocate to the caseID variable
and when the Incident is created it puts the recordID into the IncidentID variable
I then do an update on the case to set the IncidentID variable into the lookup field but it is not updating that field. Any Ideas?
I have created a process using the processor builder with the below criteria
If record type is X
and field X is false submit for approval
else
If record type is X
and field X is true submit for approval (different approval process)

The first criteria works but when setting field x to true i get (On creation)
This record is currently in an approval process. A record can be in only one approval process at a time.

We have an issue where we are attempting to use SSO but it is erroring in Salesforce. The Certifcates have not expired. Our ADFS Server is functioning successfully and it is sending the SAML without an issue.

When checking the logs we see
Signature or certificate problems
  The signature in the assertion is not valid
  Is the correct certificate supplied in the keyinfo? false

Has anyone come across this before?

 

Is there a way to create a button that takes you back to the previous record?

I have a custom button that navigates out of a case to allow us to fill another area but to go back to the case we were working on we have to press the case number in a lookup field. A button would help?

How can you test a catch exception if it looks to see if a field is set to null.
 

The trigger is
trigger UpdateEntitlement on Case (before insert,before update, after update) {

Id caseRecordTypeId = [Select id from RecordType where sObjectType = 'Case' and developerName ='Service_Desk' ].id ;
if (trigger.isBefore && trigger.isInsert) {
for (Case c : Trigger.new) {
if (c.RecordTypeID == caseRecordTypeId )
if (c.Entitlement == null) {
   try{
//c.EntitlementId = [select Id from Entitlement where Id = '550L0000000Q299IAC'].id;
c.EntitlementId = [Select Id from Entitlement Where AccountId = :c.AccountId and Default_Entitlement__c=True limit 1].id;
   }catch(QueryException e) {
System.debug('No records found. Maybe you should set it to Null:' + e);
}
}}

}}

my test class is
trigger UpdateEntitlement on Case (before insert,before update, after update) {

Id caseRecordTypeId = [Select id from RecordType where sObjectType = 'Case' and developerName ='Service_Desk' ].id ;
if (trigger.isBefore && trigger.isInsert) {
for (Case c : Trigger.new) {
if (c.RecordTypeID == caseRecordTypeId )
if (c.Entitlement == null) {
   try{
//c.EntitlementId = [select Id from Entitlement where Id = '550L0000000Q299IAC'].id;
c.EntitlementId = [Select Id from Entitlement Where AccountId = :c.AccountId and Default_Entitlement__c=True limit 1].id;
   }catch(QueryException e) {
System.debug('No records found. Maybe you should set it to Null:' + e);
}
}}

}}

I have added the below on visualforce page and added to a page layout but it does not display properly. Can you have a look and let me know what is wrong with the code or do I need to write a full visualforce page with the fields.

<apex:page standardController="Service_Request__c" showHeader="true"> <apex:pageBlock > apex:inputText value="{!Service_Request__c.Useful_SQL__c}" rendered="{!(Service_Request__c.Is_this_useful__c == true)}"/> </apex:pageBlock> </apex:page>
I have a problem where on a custom object the cancel button takes you back to the incorrect record.

To get this I have a related list within a ticket and I press New which takes me in from a reference 00012 I then press cancel and it will take me back to a reference 00001. Is there a way of making the cancel button take you back to the correct ticket.

The buttons I am using is a custom button so it populates some fields automatically.
I have two objects case and Service Request. I would like to have a field which counts the number of cases attached to the Service Request.

I am unable to have a rollup field.

Ideally i would like to have a graph that shows the number of cases and when the number increases (like a time line 9am 3 cases 10am 5 cases)
but just a field would do to count all cases added.

Does anyone know how to do this?

I have deployed a trigger to live but it seems to not populate the service Contract but in sandbox it does.
The name of the fields are the same. The trigger is
I have tested the below on our test system and it works correctly. The fields are the same in Live and Sandbox but the trigger will not populate the service contract field on a case.
I have tried removing the recordtype, using specific account but no luck on Live.
trigger UpdateServiceContract on Case (before insert,before update, after update) {
if (trigger.isBefore && trigger.isInsert) {
for (Case c : trigger.new) {
if (c.RecordTypeID == '012D0000000NWyPIAW')
if (c.service_contract__c == NULL){
try{
//c.Service_Contract__c = [select Id from ServiceContract where AccountId ='810D0000000Cfza' and Primary_Service_Contract__c = True].id;
c.Service_Contract__c = [select Id from ServiceContract where AccountId = :c.AccountId and Primary_Service_Contract__c = True limit 1].id;
}catch(QueryException e) {
//No records found. Maybe you should set it to Null
}
}
}
}
}

Is there a trigger log