-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
8Questions
-
2Replies
JS button load a specific html in same window
Hello. I hav an onclick JS button that runs a flow. Currently, it opens a new tab and executes correctly. However, I would like to load the current tab/window with the flow URL vs. opening a new tab. How do I do that?
Existing code below. Basically, I need to replace the window.open with something else.
Existing code below. Basically, I need to replace the window.open with something else.
{!RequireScript("/soap/ajax/34.0/connection.js")}
if("{!Wire_Template__c.Template_Status__c}" =="Approved"){
var base = '' //system.URL.getSalesforceBaseUrl();
var url = base+encodeURI('/flow/Wire_Template_Transfer_from_Locked_Template?WireTemplateId={!Wire_Template__c.Id}&retURL=a04/o');
window.open(url)
}
-
- Jim Parker 7
- September 22, 2017
- Like
- 0
QuickAction.QuickActionDefaultsHandler
Trying to adapt the code from:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_QuickAction_QuickActionDefaultsHandler.htm#apex_interface_QuickAction_QuickActionDefaultsHandler_Example
Effectively, on the case quick email action, it automatically strips off CC'd email addresses when you hit reply. So I am trying to pre-popualte them. The issue I am having is I don't know how to lookup the email (and the associated to, CC and from addresses) that I am replying to on the case or the most recent email that is registered on the case. Please help!
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_QuickAction_QuickActionDefaultsHandler.htm#apex_interface_QuickAction_QuickActionDefaultsHandler_Example
Effectively, on the case quick email action, it automatically strips off CC'd email addresses when you hit reply. So I am trying to pre-popualte them. The issue I am having is I don't know how to lookup the email (and the associated to, CC and from addresses) that I am replying to on the case or the most recent email that is registered on the case. Please help!
global class EmailPublisherLoader implements QuickAction.QuickActionDefaultsHandler {
// Empty constructor
global EmailPublisherLoader() {
}
// The main interface method
global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults) {
QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = null;
// Check if the quick action is the standard Case Feed send email action
for (Integer j = 0; j < defaults.size(); j++) {
if (defaults.get(j) instanceof QuickAction.SendEmailQuickActionDefaults &&
defaults.get(j).getTargetSObject().getSObjectType() ==
EmailMessage.sObjectType &&
defaults.get(j).getActionName().equals('Case.Email') &&
defaults.get(j).getActionType().equals('Email')) {
sendEmailDefaults =
(QuickAction.SendEmailQuickActionDefaults)defaults.get(j);
break;
}
}
//If stardard case feed email action
if (sendEmailDefaults != null) {
//Find the case
Case c = [SELECT Status, Reason, SuppliedEmail, ContactEmail FROM Case
WHERE Id=:sendEmailDefaults.getContextId()];
EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();
//No idea how to get the most recent email attached to the case......
EmailMessage prevEmail = [Select ccAddresses, toAddresses, fromAddress from InboundEmail where ParentId=:sendEmailDefaults.getContextId()]
//on Page load, not reply/reply all to a message
if (sendEmailDefaults.getInReplyToId() == null) {
//Count to see if previous emails on case
Integer emailCount = [SELECT count() FROM EmailMessage
WHERE ParentId=:sendEmailDefaults.getContextId()];
//previous email attached to existing case
if (emailCount!= null && emailCount > 0) {
// Set addresses
emailMessage.ccAddress = prevEmail.CcAddress;
emailMessage.toAddress = prevEmail.fromAddress;
}
//no previous email attached
else {
emailMessage.ccAddress = '';
emailMessage.toAddress = '';
}
}
//When user hits reply or reply all
else {
// Set addresses
emailMessage.ccAddress = prevEmail.CcAddress;
emailMessage.toAddress = prevEmail.fromAddress;
}
}
}
}
-
- Jim Parker 7
- August 08, 2017
- Like
- 0
Transform Javascript to VisualForce Button
Hi everyone - trying to transform my Javascript button to a VisualForce or URL button so that is shows up in SF1. Don't really know where to start. This is the existing button.
{!RequireScript("/soap/ajax/34.0/connection.js")}
if("{!Wire_Template__c.Template_Status__c}" =="Approved"){
var base = '' //system.URL.getSalesforceBaseUrl();
var url = base+encodeURI('/flow/Wire_Template_Transfer_from_Locked_Template?WireTemplateId={!Wire_Template__c.Id}&retURL=a04/o');
window.open(url)
}
else{
alert("Please submit the template for approval prior to submitting a wire.");
}
-
- Jim Parker 7
- July 24, 2017
- Like
- 0
Case Feed Email Alert
Hello - trying to send out an email to the case creator anytime someone adds a "post" to a case on the feed view. I am however struggling. I am trying to send out an email based on an email template that already exists. Few issues that I am having - what object should I set the trigger on (FeedItem?), how do I limit the trigger to only be "posts" on Cases, how do I extract the message out of the post, how do I send an email based on an email template, and how do I include the post text in the email template? Gave it a start but got lost... Any coding help would be greatly appreciated.
trigger FeedItemAddedCase on FeedItem (after insert) {
Set<ID> feedIds = new Set<ID>();
for (FeedItem n:Trigger.new){
feedIds.add(n.parentID);
}
List<Case> caseList = new List<Case>([Select id, CaseNumber, Subject, Case_Creator_Employee_Email__c from Case where ID in:feedIds limit 1]);
EmailTemplate templateId = [Select id from EmailTemplate where name = 'Case Note Alert - Internal'];
for(Case c:caseList){
Messaging.reserveSingleEmailCapacity(1);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses;
toAddresses = new String [] {c.Case_Creator_Employee_Email__c};
mail.setToAddresses(toAddresses);
mail.setReplyTo('supportresponse@test.com');
mail.setSenderDisplayName('Test Bank');
mail.setSubject('' + case.Id);
Messaging.sendEmail(new Messaging.Email[] { mail } , true);
}
}
-
- Jim Parker 7
- July 19, 2017
- Like
- 0
Update ID Values
So I am having an issue updating a variable. In essence, I want to choose a "User" based upon a condition. If the case has an employee email address on it, then use the User that has that email address. Otherwise, use the CreatedById. I have a User record called finalUser. I created finalUser early and then am trying to update the finalUser.Id based upon those two scenarios. I verified that I have an valid ID before setting finalUser equal to that but when I check to see if finalUser was updated after with a debug, the variable is still set to null. I am new to SOQL so I am clearly doing an assignment incorrectly... Help! I commented where it is broken.
trigger CaseTeamTrigger on Case (after insert) {
/**
* Comments:
* To give visiblity into the Case records that were created by a User, we
* will add them to the CaseTeamMember list when a particular record is
* updated. The user should only be added to the CaseTeamMember table once.
*
* Additionally, add case teams based on user role.
*/
Map<Id, CaseTeamMember> membersToAdd = new Map<Id, CaseTeamMember>();
Map<Id, CaseTeamTemplate> teamsToAdd = new Map<Id, CaseTeamTemplate>();
List<User> employeeEmailSubmitter;
Id employeeEmailID;
User finalUser = new User();
UserRole userRoleID = new UserRole();
//Finds the case teams
list <CaseTeamTemplate> bethesdaTeam = [Select Id, Name from CaseTeamTemplate where Name ='Bethesda Team' limit 1];
list <CaseTeamTemplate> busDevTeam = [Select Id, Name from CaseTeamTemplate where Name ='Business Development Team' limit 1];
list <CaseTeamTemplate> commDepTeam = [Select Id, Name from CaseTeamTemplate where Name ='Commerical Deposits Team' limit 1];
list <CaseTeamTemplate> dcTeam = [Select Id, Name from CaseTeamTemplate where Name ='DC Team' limit 1];
list <CaseTeamTemplate> hcDepTeam = [Select Id, Name from CaseTeamTemplate where Name ='Healthcare Deposits Team' limit 1];
list <CaseTeamTemplate> herndonTeam = [Select Id, Name from CaseTeamTemplate where Name ='Herndon Team' limit 1];
list <CaseTeamTemplate> itTeam = [Select Id, Name from CaseTeamTemplate where Name ='IT Help Desk' limit 1];
list <CaseTeamTemplate> potomacTeam = [Select Id, Name from CaseTeamTemplate where Name ='Potomac Team' limit 1];
list <CaseTeamTemplate> rockvilleTeam = [Select Id, Name from CaseTeamTemplate where Name ='Rockville Team' limit 1];
list <CaseTeamTemplate> corpLenders = [Select Id, Name from CaseTeamTemplate where Name ='Corporate Lending Team' limit 1];
list <CaseTeamTemplate> finalTeam;
//Finds the case triggered
List<Case> cases = [Select Id, OwnerId, CreatedById, Case_Creator_Employee_Email__c
from Case where id IN :Trigger.newMap.keySet()];
//Determine case creater
for (Case c : cases) {
employeeEmailSubmitter = [Select ID, Email from User where Email =: c.Case_Creator_Employee_Email__c limit 1];
//if no results returned with an employee email match, then use CreatorID
if (employeeEmailSubmitter.isEmpty() && c.CreatedbyId != null) {
System.debug('*******************************************');
System.debug('Made it to the no employee email case - ' + c.CreatedById);
//THIS DOESN"T WORK
finalUser.Id =c.CreatedById ;
update finalUser;
System.debug('FinalUser ID - ' + finalUser.Id);
}
//If Employee Email match found, use that employee
Else if (!employeeEmailSubmitter.isEmpty()){
for (User user : employeeEmailSubmitter){
if (user.Id != null){
System.debug('*******************************************');
System.debug('Made it to the employee email match -' + user.Id);
//THIS DOESN"T WORK
finalUser.Id = user.Id;
update finalUser;
System.debug('FinalUser ID - ' + finalUser.Id);
}
}
}
}
//Determine User Role of case submitter
System.debug('*******************************************');
System.debug('Final User Role ID Name ' + finalUser.UserRoleId);
List <UserRole> userRoles = ([Select Id, Name from UserRole where Id =: finalUser.UserRoleId limit 1]);
if (!userRoles.isEmpty()){
for (UserRole role: userRoles){
userRoleID.Id = role.Id;
}
}
//map role to case team
System.debug('*******************************************');
System.debug('Role ID Name ' + UserRoleID.Id);
If (UserRoleID.Name == 'Bethesda Branch Manager') {for (CaseTeamTemplate team : bethesdaTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Bethesda Staff') {for (CaseTeamTemplate team : bethesdaTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Business Development Officers') {for (CaseTeamTemplate team : busDevTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Business Development Staff'){for (CaseTeamTemplate team : busDevTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'DC Branch Manager'){for (CaseTeamTemplate team : dcTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'DC Staff'){for (CaseTeamTemplate team : dcTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Herndon Branch Manager'){for (CaseTeamTemplate team : herndonTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Herndon Staff'){for (CaseTeamTemplate team : herndonTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Lending Branch Deposit Staff'){for (CaseTeamTemplate team : hcDepTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Potomac Branch Manager'){for (CaseTeamTemplate team : potomacTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Potomac Staff'){for (CaseTeamTemplate team : potomacTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Rockville Branch Manager'){for (CaseTeamTemplate team : rockvilleTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Rockville Staff'){for (CaseTeamTemplate team : rockvilleTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Commercial Deposits Manager'){for (CaseTeamTemplate team : commDepTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Commercial Deposits Staff'){for (CaseTeamTemplate team : commDepTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'IT Employees'){for (CaseTeamTemplate team : itTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Corporate Lenders'){for (CaseTeamTemplate team : corpLenders) finalTeam.add(team); }
//create list of new members to add
for (Case c : cases) {
if (c.Id != null && finalUser.Id!= null){
System.debug('*******************************************');
System.debug('Made it to the new member list add');
membersToAdd.put(c.Id, new CaseTeamMember(
ParentId = c.Id,
MemberId = finalUser.Id ) );
}
}
List <CaseTeamRole> caseTeamRl = [SELECT Id, Name FROM CaseTeamRole WHERE Name = 'Case Creator' LIMIT 1];
//add case creator to list
//
System.debug('*******************************************');
System.debug('Made it before IF - ' + membersToAdd.isEmpty() + ' ' + caseTeamRl.isEmpty() );
if (!membersToAdd.isEmpty() && !caseTeamRl.isEmpty()) {
try {
System.debug('*******************************************');
System.debug('Made it in Role If');
for (CaseTeamMember ctm : membersToAdd.values()) {
for (CaseTeamRole role : caseTeamRl) {
System.debug('*******************************************');
System.debug('Made it to the Case Creator List addition');
ctm.TeamRoleId = role.Id;
}
}
for (CaseTeamMember ctm : [SELECT Id, MemberId, ParentId
FROM CaseTeamMember
WHERE ParentId IN :membersToAdd.keySet()
AND MemberId =: finalUser.Id
ORDER BY ParentId]) {
System.debug('*******************************************');
System.debug('Made it to the individual user delete');
if (membersToAdd.containsKey(ctm.ParentId)) {
membersToAdd.remove(ctm.ParentId);
}
}
if (!membersToAdd.isEmpty()) {
System.debug('*******************************************');
System.debug('Made it to the individual user insert');
insert membersToAdd.values();
}
} catch (System.QueryException qe) {}
}
//add case teams
System.debug('*******************************************');
System.debug('Made it to top of teams Add if - ' + teamsToAdd.isEmpty());
if (!teamsToAdd.isEmpty()) {
try {
CaseTeamTemplateRecord caseTeamLink;
for(Case caseEval: cases){
for (CaseTeamTemplate team : finalTeam){
caseTeamLink= new CaseTeamTemplateRecord(ParentId =caseEval.Id, TeamTemplateId = team.Id );
}
}
if (caseTeamLink!=null) {
System.debug('*******************************************');
System.debug('Made it to the case team insert');
insert caseTeamLink;
}
} catch (System.QueryException qe) {}
}
}
-
- Jim Parker 7
- March 06, 2017
- Like
- 0
Update Encrypted Text Field - Compile Error
I have two fields on an account - SSN_TIN_Key__C and SSN_TIN__C; The SSN_TIN_Key__C is a cleartext text field which will be used as a unique key and wil lonly be accessible to super users. SSN_TIN__C is what will be displayed to the user and is an encrpyted text field so I can mask the field for certain users. What I want to be able to do is have users be able to update the SSN field they see (eg. SSN_TIN__C) and have that update SSN_TIN_Key__C. Similarly, if on an upsert, if SSN_TIN_Key__C changes (or is created), I want to update the field users can see SSN_TIN__C. I created a trigger as process won't let you do ischanged on an encrpyted field. However, I get a failure message that says
common.apex.runtime.impl.DmlExecutionException: Update failed. First exception on row 0 with id XXX; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = XXX) is currently in trigger RelationshipTrigger, therefore it cannot recursively update itself: []"|0x6c21e43e
What am I doing wrong?
common.apex.runtime.impl.DmlExecutionException: Update failed. First exception on row 0 with id XXX; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = XXX) is currently in trigger RelationshipTrigger, therefore it cannot recursively update itself: []"|0x6c21e43e
What am I doing wrong?
public class RelationshipUtil {
public static void SSNKeyChanged (List<Account> incomingAcct) {
try {
System.debug('Got to SSNKeyChanged entered');
Set<Id> st_ParentId = new Set<Id>();
for(Account acctsEvaled : incomingAcct)
{
st_ParentId.add(acctsEvaled.Id);
}
Map<Id, Account> relatedAcctMap;
if(st_ParentId!=null && !st_ParentId.isEmpty())
{
relatedAcctMap = new Map<Id, Account>([SELECT Id, SSN_TIN__c, SSN_TIN_Key__c
FROM Account
WHERE Id IN :st_ParentId limit 1]);
System.debug('Got to SSNKeyChanged lookup');
}
for (Account acctsEvaled : incomingAcct)
{
System.debug('Got to SSNKeyChanged foor loop');
if(relatedAcctMap!=null && relatedAcctMap.containsKey(acctsEvaled.Id))
{
//Updates the displayed SSN based upon the new Key
System.debug('Got to SSNKeyChanged entered for if');
relatedAcctMap.get(acctsEvaled.Id).SSN_TIN__c = relatedAcctMap.get(acctsEvaled.Id).SSN_TIN_Key__c;
System.debug('Got to SSNKeyChanged set');
}
}
if(relatedAcctMap!=null && relatedAcctMap.values()!=null)
{
update relatedAcctMap.values();
System.debug('Got to SSNKeyChanged update');
}
} catch (Exception e) {
System.debug('Issue with SSNKeyChanged: ' + e.getMessage());
}
}
public static void SSNDisplayChanged (List<Account> incomingAcct) {
try {
Set<Id> st_ParentId = new Set<Id>();
for(Account acctsEvaled : incomingAcct)
{
st_ParentId.add(acctsEvaled.Id);
}
Map<Id, Account> relatedAcctMap;
if(st_ParentId!=null && !st_ParentId.isEmpty())
{
relatedAcctMap = new Map<Id, Account>([SELECT Id, SSN_TIN__c, SSN_TIN_Key__c
FROM Account
WHERE Id IN :st_ParentId limit 1]);
}
for (Account acctsEvaled : incomingAcct)
{
if(relatedAcctMap!=null && relatedAcctMap.containsKey(acctsEvaled.Id))
{
//Updates the Key with the new values input by the user
relatedAcctMap.get(acctsEvaled.Id).SSN_TIN_Key__c = relatedAcctMap.get(acctsEvaled.Id).SSN_TIN__c;
System.debug('Got to SSNDisplayChanged set');
}
}
if(relatedAcctMap!=null && relatedAcctMap.values()!=null)
{
System.debug('Got to SSNDisplayChanged update');
update relatedAcctMap.values();
}
} catch (Exception e) {
System.debug('Issue with SSNDisplayChanged: ' + e.getMessage());
}
}
}
trigger RelationshipTrigger on Account (before insert, before update) {
System.debug('Start Relationship Before Trigger');
List<Account> changedSSNKey = new List<Account>();
List<Account> changedSSNDisplay = new List<Account>();
for (Account acct : Trigger.new) {
Account oldAcct = Trigger.oldMap.get(acct.Id);
String oldSSNDisplay = oldAcct.SSN_TIN__c;
String oldSSNKey = oldAcct.SSN_TIN_Key__c;
System.debug('Old SSN_TIN__C = ' + oldSSNDisplay);
System.debug('Old SSN_TIN_Key__C = ' + oldSSNKey);
//Checks to see if the displayed TIN changed (eg. user put in new value)
if(oldSSNDisplay != acct.SSN_TIN__c)
{
changedSSNDisplay.add(acct);
//If Displayed SSN changed, then need to update the unique key
if (changedSSNDisplay.isEmpty() == false)
RelationshipUtil.SSNDisplayChanged(changedSSNDisplay);
}
//Checks to see if unique key changed
if(oldSSNKey != acct.SSN_TIN_KEY__C)
{
changedSSNKey.add(acct);
//If SSN Key changed, then need to updated the displayed value
if (changedSSNKey.isEmpty() == false)
RelationshipUtil.SSNKeyChanged(changedSSNKey);
}
}
}
-
- Jim Parker 7
- March 02, 2017
- Like
- 0
Invalid Initial Value Type List for List - Compile Error
Getting a compile error - Invalid Initial Value Type List for List. Line 14 (commented below). In essence, I have a trigger on dsfs__DocuSign_Status__c. dsfs__DocuSign_Status__c has a field dsfs__Case__c which is an ID of a case. Anytime the trigger occurs, I want to set the "Status" field on the case identified by dsfs__Case__c to newStatus. Any thoughts on what I am doing wrong?
public class DocusignStatusUtil {
public static void updateCaseStatus (List<dsfs__DocuSign_Status__c> envelopes, String newStatus) {
try {
Set<Id> st_ParentId = new Set<Id>();
for(dsfs__DocuSign_Status__c envelopesEvaluated : envelopes)
{
st_ParentId.add(envelopesEvaluated.dsfs__Case__c);
}
List<Id> relatedCasesMap;
if(st_ParentId!=null && !st_ParentId.isEmpty())
{
//this is where the error is
relatedCasesMap = new List<Id>([SELECT Id
FROM Case
WHERE Id IN :st_ParentId limit 1]);
}
for (dsfs__DocuSign_Status__c envelopesEvaluated : envelopes)
{
if(relatedCasesMap!=null && relatedCasesMap.containsKey(envelopesEvaluated.dsfs__Case__c))
{
relatedCasesMap.get(envelopesEvaluated.dsfs__Case__c).Status = newStatus;
}
}
if(relatedCasesMap!=null && relatedCasesMap.values()!=null)
update relatedCasesMap.values();
} catch (Exception e) {
System.debug('Issue with the Horizon Case Update: ' + e.getMessage());
}
}
}
-
- Jim Parker 7
- February 21, 2017
- Like
- 0
Sobject Coding Issues
Having a coding issue that I can't figure out.... New to this and feel like I am missing something.
Creating a trigger on a joiner object (Horizon_Account_Cases__c) between cases and a custom object (Horizon_Account__c) which has only two fields (Horizon_Acct__c and Case__c) which are unique keys for the ID's on the two related object cases. Upon triggering on Horizon_Account_Cases__c, the related case (eg Case__C) should have its field Related_Horizon_Account__c updated with the value in the joiner object that triggered (Horizon_Acct__c). Can't get it to compile and need help! I am sure I am missing something very obvious...
public class horizonCaseLinkUtil {
public static void addHorizonToCase (List<sObject> linkIds) {
try {
List<Case> casesToUpdate = [select Id
from Case caseUsed
where Id in :linkIds.Case__c
limit 1];
List<Horizon_Account__c> horizonAccounts = [select Id
from Horizon_Account__c hzActCase
where Id in :linkIds.Horizon_Acct__c
limit 1];
for (Case cases : casesToUpdate)
{
for (Horizon_Account__c horizon : horizonAccounts)
{
cases.Related_Horizon_Account__c = horizon.Id;
}
}
update casesToUpdate;
}
catch (Exception e) {
System.debut('Issue with the Horizon Case Update: ' +e.getMessage() );
}
}
}
trigger HorizonAcctCaseLinked on Horizon_Account_Cases__c (after insert, after update) {
List<sObject> linkedHorizonCase = new List<sObject>();
for (Horizon_Account_Cases__c hzActCase : Trigger.new)
linkedHorizonCase.add(hzActCase);
if (linkedHorizonCase.isEmpty() == false)
{
horizonCaseLinkUtil.addHorizonToCase(linkedHorizonCase);
}
}
@isTest(SeeAllData=true)
public class HorizonCaseLinkTest {
static testMethod void caseLinkTestMethod() {
List<sObject> sourceList = [SELECT Id
FROM Horizon_Account_Cases__c LIMIT 1];
Case c = new Case(Subject = 'Test Case');
Horizon_Account__c horizonAcct = new Horizon_Account__c (Name='Test Horizon Acct');
if(sourceList.size() == 0) {
sourceList.add(
new Horizon_Account_Cases__c(Case__c =c.Id, Horizon_Acct__c=horizonAcct.Name)
);
}
horizonCaseLinkUtil.addHorizonToCase( sourceList );
}
}
Creating a trigger on a joiner object (Horizon_Account_Cases__c) between cases and a custom object (Horizon_Account__c) which has only two fields (Horizon_Acct__c and Case__c) which are unique keys for the ID's on the two related object cases. Upon triggering on Horizon_Account_Cases__c, the related case (eg Case__C) should have its field Related_Horizon_Account__c updated with the value in the joiner object that triggered (Horizon_Acct__c). Can't get it to compile and need help! I am sure I am missing something very obvious...
public class horizonCaseLinkUtil {
public static void addHorizonToCase (List<sObject> linkIds) {
try {
List<Case> casesToUpdate = [select Id
from Case caseUsed
where Id in :linkIds.Case__c
limit 1];
List<Horizon_Account__c> horizonAccounts = [select Id
from Horizon_Account__c hzActCase
where Id in :linkIds.Horizon_Acct__c
limit 1];
for (Case cases : casesToUpdate)
{
for (Horizon_Account__c horizon : horizonAccounts)
{
cases.Related_Horizon_Account__c = horizon.Id;
}
}
update casesToUpdate;
}
catch (Exception e) {
System.debut('Issue with the Horizon Case Update: ' +e.getMessage() );
}
}
}
trigger HorizonAcctCaseLinked on Horizon_Account_Cases__c (after insert, after update) {
List<sObject> linkedHorizonCase = new List<sObject>();
for (Horizon_Account_Cases__c hzActCase : Trigger.new)
linkedHorizonCase.add(hzActCase);
if (linkedHorizonCase.isEmpty() == false)
{
horizonCaseLinkUtil.addHorizonToCase(linkedHorizonCase);
}
}
@isTest(SeeAllData=true)
public class HorizonCaseLinkTest {
static testMethod void caseLinkTestMethod() {
List<sObject> sourceList = [SELECT Id
FROM Horizon_Account_Cases__c LIMIT 1];
Case c = new Case(Subject = 'Test Case');
Horizon_Account__c horizonAcct = new Horizon_Account__c (Name='Test Horizon Acct');
if(sourceList.size() == 0) {
sourceList.add(
new Horizon_Account_Cases__c(Case__c =c.Id, Horizon_Acct__c=horizonAcct.Name)
);
}
horizonCaseLinkUtil.addHorizonToCase( sourceList );
}
}
-
- Jim Parker 7
- February 17, 2017
- Like
- 0
Update ID Values
So I am having an issue updating a variable. In essence, I want to choose a "User" based upon a condition. If the case has an employee email address on it, then use the User that has that email address. Otherwise, use the CreatedById. I have a User record called finalUser. I created finalUser early and then am trying to update the finalUser.Id based upon those two scenarios. I verified that I have an valid ID before setting finalUser equal to that but when I check to see if finalUser was updated after with a debug, the variable is still set to null. I am new to SOQL so I am clearly doing an assignment incorrectly... Help! I commented where it is broken.
trigger CaseTeamTrigger on Case (after insert) {
/**
* Comments:
* To give visiblity into the Case records that were created by a User, we
* will add them to the CaseTeamMember list when a particular record is
* updated. The user should only be added to the CaseTeamMember table once.
*
* Additionally, add case teams based on user role.
*/
Map<Id, CaseTeamMember> membersToAdd = new Map<Id, CaseTeamMember>();
Map<Id, CaseTeamTemplate> teamsToAdd = new Map<Id, CaseTeamTemplate>();
List<User> employeeEmailSubmitter;
Id employeeEmailID;
User finalUser = new User();
UserRole userRoleID = new UserRole();
//Finds the case teams
list <CaseTeamTemplate> bethesdaTeam = [Select Id, Name from CaseTeamTemplate where Name ='Bethesda Team' limit 1];
list <CaseTeamTemplate> busDevTeam = [Select Id, Name from CaseTeamTemplate where Name ='Business Development Team' limit 1];
list <CaseTeamTemplate> commDepTeam = [Select Id, Name from CaseTeamTemplate where Name ='Commerical Deposits Team' limit 1];
list <CaseTeamTemplate> dcTeam = [Select Id, Name from CaseTeamTemplate where Name ='DC Team' limit 1];
list <CaseTeamTemplate> hcDepTeam = [Select Id, Name from CaseTeamTemplate where Name ='Healthcare Deposits Team' limit 1];
list <CaseTeamTemplate> herndonTeam = [Select Id, Name from CaseTeamTemplate where Name ='Herndon Team' limit 1];
list <CaseTeamTemplate> itTeam = [Select Id, Name from CaseTeamTemplate where Name ='IT Help Desk' limit 1];
list <CaseTeamTemplate> potomacTeam = [Select Id, Name from CaseTeamTemplate where Name ='Potomac Team' limit 1];
list <CaseTeamTemplate> rockvilleTeam = [Select Id, Name from CaseTeamTemplate where Name ='Rockville Team' limit 1];
list <CaseTeamTemplate> corpLenders = [Select Id, Name from CaseTeamTemplate where Name ='Corporate Lending Team' limit 1];
list <CaseTeamTemplate> finalTeam;
//Finds the case triggered
List<Case> cases = [Select Id, OwnerId, CreatedById, Case_Creator_Employee_Email__c
from Case where id IN :Trigger.newMap.keySet()];
//Determine case creater
for (Case c : cases) {
employeeEmailSubmitter = [Select ID, Email from User where Email =: c.Case_Creator_Employee_Email__c limit 1];
//if no results returned with an employee email match, then use CreatorID
if (employeeEmailSubmitter.isEmpty() && c.CreatedbyId != null) {
System.debug('*******************************************');
System.debug('Made it to the no employee email case - ' + c.CreatedById);
//THIS DOESN"T WORK
finalUser.Id =c.CreatedById ;
update finalUser;
System.debug('FinalUser ID - ' + finalUser.Id);
}
//If Employee Email match found, use that employee
Else if (!employeeEmailSubmitter.isEmpty()){
for (User user : employeeEmailSubmitter){
if (user.Id != null){
System.debug('*******************************************');
System.debug('Made it to the employee email match -' + user.Id);
//THIS DOESN"T WORK
finalUser.Id = user.Id;
update finalUser;
System.debug('FinalUser ID - ' + finalUser.Id);
}
}
}
}
//Determine User Role of case submitter
System.debug('*******************************************');
System.debug('Final User Role ID Name ' + finalUser.UserRoleId);
List <UserRole> userRoles = ([Select Id, Name from UserRole where Id =: finalUser.UserRoleId limit 1]);
if (!userRoles.isEmpty()){
for (UserRole role: userRoles){
userRoleID.Id = role.Id;
}
}
//map role to case team
System.debug('*******************************************');
System.debug('Role ID Name ' + UserRoleID.Id);
If (UserRoleID.Name == 'Bethesda Branch Manager') {for (CaseTeamTemplate team : bethesdaTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Bethesda Staff') {for (CaseTeamTemplate team : bethesdaTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Business Development Officers') {for (CaseTeamTemplate team : busDevTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Business Development Staff'){for (CaseTeamTemplate team : busDevTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'DC Branch Manager'){for (CaseTeamTemplate team : dcTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'DC Staff'){for (CaseTeamTemplate team : dcTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Herndon Branch Manager'){for (CaseTeamTemplate team : herndonTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Herndon Staff'){for (CaseTeamTemplate team : herndonTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Lending Branch Deposit Staff'){for (CaseTeamTemplate team : hcDepTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Potomac Branch Manager'){for (CaseTeamTemplate team : potomacTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Potomac Staff'){for (CaseTeamTemplate team : potomacTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Rockville Branch Manager'){for (CaseTeamTemplate team : rockvilleTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Rockville Staff'){for (CaseTeamTemplate team : rockvilleTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Commercial Deposits Manager'){for (CaseTeamTemplate team : commDepTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Commercial Deposits Staff'){for (CaseTeamTemplate team : commDepTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'IT Employees'){for (CaseTeamTemplate team : itTeam) finalTeam.add(team); }
else if (UserRoleID.Name == 'Corporate Lenders'){for (CaseTeamTemplate team : corpLenders) finalTeam.add(team); }
//create list of new members to add
for (Case c : cases) {
if (c.Id != null && finalUser.Id!= null){
System.debug('*******************************************');
System.debug('Made it to the new member list add');
membersToAdd.put(c.Id, new CaseTeamMember(
ParentId = c.Id,
MemberId = finalUser.Id ) );
}
}
List <CaseTeamRole> caseTeamRl = [SELECT Id, Name FROM CaseTeamRole WHERE Name = 'Case Creator' LIMIT 1];
//add case creator to list
//
System.debug('*******************************************');
System.debug('Made it before IF - ' + membersToAdd.isEmpty() + ' ' + caseTeamRl.isEmpty() );
if (!membersToAdd.isEmpty() && !caseTeamRl.isEmpty()) {
try {
System.debug('*******************************************');
System.debug('Made it in Role If');
for (CaseTeamMember ctm : membersToAdd.values()) {
for (CaseTeamRole role : caseTeamRl) {
System.debug('*******************************************');
System.debug('Made it to the Case Creator List addition');
ctm.TeamRoleId = role.Id;
}
}
for (CaseTeamMember ctm : [SELECT Id, MemberId, ParentId
FROM CaseTeamMember
WHERE ParentId IN :membersToAdd.keySet()
AND MemberId =: finalUser.Id
ORDER BY ParentId]) {
System.debug('*******************************************');
System.debug('Made it to the individual user delete');
if (membersToAdd.containsKey(ctm.ParentId)) {
membersToAdd.remove(ctm.ParentId);
}
}
if (!membersToAdd.isEmpty()) {
System.debug('*******************************************');
System.debug('Made it to the individual user insert');
insert membersToAdd.values();
}
} catch (System.QueryException qe) {}
}
//add case teams
System.debug('*******************************************');
System.debug('Made it to top of teams Add if - ' + teamsToAdd.isEmpty());
if (!teamsToAdd.isEmpty()) {
try {
CaseTeamTemplateRecord caseTeamLink;
for(Case caseEval: cases){
for (CaseTeamTemplate team : finalTeam){
caseTeamLink= new CaseTeamTemplateRecord(ParentId =caseEval.Id, TeamTemplateId = team.Id );
}
}
if (caseTeamLink!=null) {
System.debug('*******************************************');
System.debug('Made it to the case team insert');
insert caseTeamLink;
}
} catch (System.QueryException qe) {}
}
}

- Jim Parker 7
- March 06, 2017
- Like
- 0
Update Encrypted Text Field - Compile Error
I have two fields on an account - SSN_TIN_Key__C and SSN_TIN__C; The SSN_TIN_Key__C is a cleartext text field which will be used as a unique key and wil lonly be accessible to super users. SSN_TIN__C is what will be displayed to the user and is an encrpyted text field so I can mask the field for certain users. What I want to be able to do is have users be able to update the SSN field they see (eg. SSN_TIN__C) and have that update SSN_TIN_Key__C. Similarly, if on an upsert, if SSN_TIN_Key__C changes (or is created), I want to update the field users can see SSN_TIN__C. I created a trigger as process won't let you do ischanged on an encrpyted field. However, I get a failure message that says
common.apex.runtime.impl.DmlExecutionException: Update failed. First exception on row 0 with id XXX; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = XXX) is currently in trigger RelationshipTrigger, therefore it cannot recursively update itself: []"|0x6c21e43e
What am I doing wrong?
common.apex.runtime.impl.DmlExecutionException: Update failed. First exception on row 0 with id XXX; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = XXX) is currently in trigger RelationshipTrigger, therefore it cannot recursively update itself: []"|0x6c21e43e
What am I doing wrong?
public class RelationshipUtil {
public static void SSNKeyChanged (List<Account> incomingAcct) {
try {
System.debug('Got to SSNKeyChanged entered');
Set<Id> st_ParentId = new Set<Id>();
for(Account acctsEvaled : incomingAcct)
{
st_ParentId.add(acctsEvaled.Id);
}
Map<Id, Account> relatedAcctMap;
if(st_ParentId!=null && !st_ParentId.isEmpty())
{
relatedAcctMap = new Map<Id, Account>([SELECT Id, SSN_TIN__c, SSN_TIN_Key__c
FROM Account
WHERE Id IN :st_ParentId limit 1]);
System.debug('Got to SSNKeyChanged lookup');
}
for (Account acctsEvaled : incomingAcct)
{
System.debug('Got to SSNKeyChanged foor loop');
if(relatedAcctMap!=null && relatedAcctMap.containsKey(acctsEvaled.Id))
{
//Updates the displayed SSN based upon the new Key
System.debug('Got to SSNKeyChanged entered for if');
relatedAcctMap.get(acctsEvaled.Id).SSN_TIN__c = relatedAcctMap.get(acctsEvaled.Id).SSN_TIN_Key__c;
System.debug('Got to SSNKeyChanged set');
}
}
if(relatedAcctMap!=null && relatedAcctMap.values()!=null)
{
update relatedAcctMap.values();
System.debug('Got to SSNKeyChanged update');
}
} catch (Exception e) {
System.debug('Issue with SSNKeyChanged: ' + e.getMessage());
}
}
public static void SSNDisplayChanged (List<Account> incomingAcct) {
try {
Set<Id> st_ParentId = new Set<Id>();
for(Account acctsEvaled : incomingAcct)
{
st_ParentId.add(acctsEvaled.Id);
}
Map<Id, Account> relatedAcctMap;
if(st_ParentId!=null && !st_ParentId.isEmpty())
{
relatedAcctMap = new Map<Id, Account>([SELECT Id, SSN_TIN__c, SSN_TIN_Key__c
FROM Account
WHERE Id IN :st_ParentId limit 1]);
}
for (Account acctsEvaled : incomingAcct)
{
if(relatedAcctMap!=null && relatedAcctMap.containsKey(acctsEvaled.Id))
{
//Updates the Key with the new values input by the user
relatedAcctMap.get(acctsEvaled.Id).SSN_TIN_Key__c = relatedAcctMap.get(acctsEvaled.Id).SSN_TIN__c;
System.debug('Got to SSNDisplayChanged set');
}
}
if(relatedAcctMap!=null && relatedAcctMap.values()!=null)
{
System.debug('Got to SSNDisplayChanged update');
update relatedAcctMap.values();
}
} catch (Exception e) {
System.debug('Issue with SSNDisplayChanged: ' + e.getMessage());
}
}
}
trigger RelationshipTrigger on Account (before insert, before update) {
System.debug('Start Relationship Before Trigger');
List<Account> changedSSNKey = new List<Account>();
List<Account> changedSSNDisplay = new List<Account>();
for (Account acct : Trigger.new) {
Account oldAcct = Trigger.oldMap.get(acct.Id);
String oldSSNDisplay = oldAcct.SSN_TIN__c;
String oldSSNKey = oldAcct.SSN_TIN_Key__c;
System.debug('Old SSN_TIN__C = ' + oldSSNDisplay);
System.debug('Old SSN_TIN_Key__C = ' + oldSSNKey);
//Checks to see if the displayed TIN changed (eg. user put in new value)
if(oldSSNDisplay != acct.SSN_TIN__c)
{
changedSSNDisplay.add(acct);
//If Displayed SSN changed, then need to update the unique key
if (changedSSNDisplay.isEmpty() == false)
RelationshipUtil.SSNDisplayChanged(changedSSNDisplay);
}
//Checks to see if unique key changed
if(oldSSNKey != acct.SSN_TIN_KEY__C)
{
changedSSNKey.add(acct);
//If SSN Key changed, then need to updated the displayed value
if (changedSSNKey.isEmpty() == false)
RelationshipUtil.SSNKeyChanged(changedSSNKey);
}
}
}

- Jim Parker 7
- March 02, 2017
- Like
- 0