-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
17Questions
-
25Replies
Need help on case deflection and fetching data from custom object while on case creation form in community
Hi, i have created a custom object called template where i have created few fields same as case obejct. whenever i create case through community, while typing in subject field it should show me all related template name and once i select any template it should autofill others fields on case with template fields.
I need to achieve this in community case creation page without affecting Subject field's case deflection functionality.
Please suggest. Any help will be apprecciated.
I need to achieve this in community case creation page without affecting Subject field's case deflection functionality.
Please suggest. Any help will be apprecciated.
- Snehal Gaware 15
- July 31, 2019
- Like
- 0
test class for before update trigger on custom object
Hi, i need help to write test class for following trigger.
Thanks in advance.
trigger UpdateProblemTaskOwner on SC_Problem_Task__c (after insert, after update, after delete,before update) { if (Trigger.isBefore && Trigger.isUpdate) { for(SC_Problem_Task__c pt : Trigger.new) { List<Group> qid = [select Id from Group where Name = : pt.Assignment_Group__c and Type = 'Queue']; for(Group g : qid) { pt.OwnerId = g.id; System.debug('updated'); } } } }
Thanks in advance.
- Snehal Gaware 15
- February 27, 2019
- Like
- 0
test class coverage is showing constant is 53 only.
Hi, i need help on test class of below trigger.
trigger CaseTrigger on Case (before insert,before update, after update) { if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert)) { List<Id> contactIds = new List<Id>(); List<Id> acctIds = new List<Id>(); for (Case c: Trigger.new){ if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){ contactIds.add(c.ContactId); acctIds.add(c.AccountId); } } if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){ /* Added check for active entitlement */ List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e Where e.ContactId in:contactIds And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today]; if(entlContacts.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.ContactId!= null){ for(EntitlementContact ec:entlContacts){ if(ec.ContactId==c.ContactId){ c.EntitlementId = ec.EntitlementId; if(c.AssetId==null && ec.Entitlement.AssetId!=null) c.AssetId=ec.Entitlement.AssetId; break; } } // end for entitlement } } // end for case } else{ List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId From Entitlement e Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today]; if(entls.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.AccountId!= null){ for(Entitlement e:entls){ if(e.AccountId==c.AccountId){ c.EntitlementId = e.Id; if(c.AssetId==null && e.AssetId!=null) c.AssetId=e.AssetId; break; } } // end for } } // end for } } } // end if(contactIds.isEmpty()==false) } if(Trigger.isBefore && Trigger.isUpdate) { System.debug('entered if condition'); for(Case c : Trigger.new) { if (c.Assignment_Group__c != trigger.oldMap.get(c.Id).Assignment_Group__c){ System.debug('Updating logic'); List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue']; for(Group g : qid) { c.OwnerId = g.id; System.debug('updated'); } }} } if(Trigger.isBefore && Trigger.isUpdate) { for(Case c : Trigger.new) { if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg') { c.Group_Manager_Email__c = 'sargware@gmail.com'; c.Escalation_Level_2_Email__c ='sargware@gmail.com'; c.Escalation_Level_3_Email__c='sargware@gmail.com'; } } } if(Trigger.isBefore && Trigger.isUpdate) { for(Case c : Trigger.new) { if(c.Internal_Impact__c == 'Low' && c.Internal_Urgency__c=='Low') { c.Priority='Planning'; } if(c.Internal_Impact__c == 'High' && c.Internal_Urgency__c=='High') { c.Priority='Critical'; } if(c.Status=='Pending User' || c.Status=='Pending Vendor') { c.IsStopped = True; } } } if((Trigger.isAfter && Trigger.isUpdate)) { Set<Id> Ids = new Set<Id>(); Set<Id> IdR = new Set<Id>(); Set<Id> IdC = new Set<Id>(); List<SC_Problem_Case_Link__c> scprblm = new List<SC_Problem_Case_Link__c>(); List<SC_Problem_Case_Link__c> scprblmo = new List<SC_Problem_Case_Link__c>(); List<SC_Problem_Case_Link__c> scprblmc = new List<SC_Problem_Case_Link__c>(); for (Case cs: Trigger.new) { Case oldLead = Trigger.oldMap.get(cs.Id); if (cs.Status == 'Tested' && Trigger.oldMap.get(oldLead .Id).Status=='Ready for Testing') { Ids.add(cs.Id); } if (cs.Status == 'ReOpen') { IdR.add(cs.Id); } if (cs.Status == 'Closed') { IdC.add(cs.Id); } } for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Ready for Testing' AND Case__c in :Ids]) { if (rateSheet.Status__c != 'Tested') { rateSheet.Status__c = 'Tested'; //rateSheet.Case__c.Status= 'Awaiting Deployment'; scprblm.add(rateSheet); } } if (!scprblm.isEmpty()) { update scprblm; } for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdR]) { // List<SC_Problem_Case_Link__c> accts = [Select Id, Status__c from SC_Problem_Case_Link__c where Id in : Trigger.old]; if (rateSheet.Status__c != 'Open') { rateSheet.Status__c = 'Open'; scprblmo.add(rateSheet); } } if (!scprblmo.isEmpty()) { update scprblmo; } for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdC]) { if (rateSheet.Status__c != 'Closed') { rateSheet.Status__c = 'Closed'; scprblmc.add(rateSheet); } } if (!scprblmc.isEmpty()) { update scprblmc; } } }test class :
@isTest public class CaseTrigger_Test { @isTest static void caseTriggerTest(){ Account acc=new Account(); acc.name = 'Acc Name'; insert acc; Contact con= new Contact(); con.lastname = 'con lName'; con.AccountId= acc.Id; insert con; Entitlement ent = new Entitlement(Name='test2', AccountId=acc.Id, StartDate=Date.valueof(System.now().addDays(-10)), EndDate=Date.valueof(System.now().addYears(3))); insert ent; EntitlementContact ec = new EntitlementContact(EntitlementId=ent.Id, ContactId=con.Id); insert ec; case c=new case(); c.AccountId = acc.Id; c.ContactId = con.Id; c.Assignment_Group__c = 'Tech Support'; insert c; c.Assignment_Group__c = 'GD-DB'; update c; } @isTest static void caseTriggerTest1(){ Account acc=new Account(); acc.name = 'Acc Name'; insert acc; Contact con= new Contact(); con.lastname = 'con lName'; con.AccountId= acc.Id; insert con; Entitlement ent = new Entitlement(Name='test2', AccountId=acc.Id, StartDate=Date.valueof(System.now().addDays(-10)), EndDate=Date.valueof(System.now().addYears(3))); insert ent; case c=new case(); c.AccountId = acc.Id; c.ContactId = con.Id; insert c; } @isTest static void caseTriggerTest2(){ Account acc=new Account(); acc.name = 'Acc Name'; insert acc; Contact con= new Contact(); con.lastname = 'con lName'; con.AccountId= acc.Id; insert con; Entitlement ent = new Entitlement(Name='test2', AccountId=acc.Id, StartDate=Date.valueof(System.now().addDays(-10)), EndDate=Date.valueof(System.now().addYears(3))); insert ent; case c=new case(); c.AccountId = acc.Id; c.ContactId = con.Id; c.Internal_Impact__c = 'Low'; c.Priority = 'Medium'; insert c; SC_Problem_Management__c sc=new SC_Problem_Management__c(); sc.Products__c= 'AutoClass'; sc.Impact__c='Critical'; sc.Urgency__c='Critical'; sc.Priority__c='Critical'; insert sc; SC_Problem_Case_Link__c scpl=new SC_Problem_Case_Link__c(); scpl.Case__c=c.Id; scpl.SC_Problem_Management__c= sc.Id; scpl.Status__c='Open'; insert scpl; if(scpl.Status__c!='Resolved'){ scpl.Status__c='Resolved';} update scpl; c.Priority = 'Planning'; update c; } }
- Snehal Gaware 15
- February 27, 2019
- Like
- 0
test class for after update trigger on case
Hi team,
I need help in writting test class for after update trigger on case.
Thanks in advance. Any help will be appreciated.
I need help in writting test class for after update trigger on case.
trigger caseOwnerUpdate on Case (after update) { List<Case> updateCS = new List<Case>(); Map<Id,Case> cases = new Map<Id,Case>(); for (Case cs : Trigger.new) { if(Trigger.isUpdate) { System.debug('>>>>> Owner ID: '+cs.ownerId+' Temp Owner ID: '+cs.TempOwnerId__c); if(cs.TempOwnerId__c <> null && cs.TempOwnerId__c <> '' && cs.OwnerId != trigger.oldMap.Get(cs.Id).OwnerId) { system.debug('pleasecheck'+trigger.oldMap.Get(cs.Id).OwnerId); if(cs.OwnerId <> cs.TempOwnerId__c) { cases.put(cs.id,cs); } } } } if (cases.isEmpty()) return; for (Case cs : [SELECT OwnerId,TempOwnerId__c FROM Case WHERE id in :cases.keySet()]) { cs.OwnerId = cases.get(cs.Id).TempOwnerId__c; system.debug('pleasecheck2'+ cs.OwnerId); cs.TempOwnerId__c = 'SKIP'; //flag to stop infinite loop upon update updateCS.add(cs); } System.debug('>>>>>Update Cases: '+updateCS); // //Update last assignment for Assignment Group in batch // if (updateCS.size()>0) { try { update updateCS; } catch (Exception e){ } } }
Thanks in advance. Any help will be appreciated.
- Snehal Gaware 15
- February 27, 2019
- Like
- 0
test class for apex class.. need help
Hi,
I need help in writting test class for following class.
Thanks in advance. any help will be appreciated.
I need help in writting test class for following class.
public class Populate { public Case cs{get;set;} public SC_Problem_Management__c prblm{get;set;} public ApexPages.StandardController stdCntrlr {get; set;} public Populate(ApexPages.StandardController controller) { cs = new Case(); prblm = new SC_Problem_Management__c(); prblm = (SC_Problem_Management__c)controller.getRecord(); //Get the ID of Currently present case on vf page String csId = [SELECT Id FROM Case WHERE Id =: prblm.Case__c].Id; System.debug('testing'+ csId); prblm.Case__c= csId; if(csId != null) { //calling autofilling method autoCal(); } } //function is called from actionsupport event public void autoCal() { Id caseid = prblm.Case__c; // collecting case id from visualforce page if(caseid!=null){ List<Case> caseLst = [select id,Products__c,Componet__c ,Feature__c,Status,Priority,Subject,Description__c,Assignment_Group__c from Case where id=:caseid]; system.debug('Product'+ caseLst[0].Products__c); if(!caseLst.isEmpty()) { prblm.Products__c= caseLst[0].Products__c; prblm.Component__c = caseLst[0].Componet__c; prblm.Feature__c = caseLst[0].Feature__c; prblm.Status__c = caseLst[0].Status; prblm.Priority__c = caseLst[0].Priority; prblm.Title__c=caseLst[0].Subject; prblm.Issue_Escape__c=caseLst[0].Assignment_Group__c; prblm.Description__c= caseLst[0].Description__c; } } } public pagereference Save() { insert prblm; pagereference pr = new pagereference('/'+prblm.id); System.debug('pagereference/////'+pr); return pr; } }
Thanks in advance. any help will be appreciated.
- Snehal Gaware 15
- February 27, 2019
- Like
- 0
help needed on after update trigger which is not updating field value
Hi I have written a trigger where Case is parent object and SC_Problem_Case_Link__c is child object. this trigger working fine when child object is having any status other than Ready for testing, at that by using this trigger i am bale to change the status as tested.
But when status of child object is 'Ready For testing' i am not able to change it to tested.
is there any suggestion how to resolve this.
But when status of child object is 'Ready For testing' i am not able to change it to tested.
if((Trigger.isAfter && Trigger.isUpdate)) { Set<Id> Ids = new Set<Id>(); List<SC_Problem_Case_Link__c> scprblm = new List<SC_Problem_Case_Link__c>(); for (Case cs: Trigger.new) { Case oldLead = Trigger.oldMap.get(cs.Id); if (cs.Status == 'Tested') { Ids.add(cs.Id); } } for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Case__c in :Ids]) { // List<SC_Problem_Case_Link__c> accts = [Select Id, Status__c from SC_Problem_Case_Link__c where Id in : Trigger.old]; if (rateSheet.Status__c != 'Tested') { rateSheet.Status__c = 'Tested'; scprblm.add(rateSheet); } } if (!scprblm.isEmpty()) { update scprblm; }}
is there any suggestion how to resolve this.
- Snehal Gaware 15
- February 25, 2019
- Like
- 0
not able to create record through vf page on object tab. getting error as "List has no rows for assignment to SObject ".
Hi i have created vf page and controller to override new button of custom object (Problem). So whenever i am able to create problem through case and it is working as expected. but when i am creating problem though it's tab i am getting error as : "List has no rows for assignment to SObject " . Please suggest.
controller :
controller :
public class Populate { public Case cs{get;set;} public SC_Problem_Management__c prblm{get;set;} public ApexPages.StandardController stdCntrlr {get; set;} public Populate(ApexPages.StandardController controller) { cs = new Case(); prblm = new SC_Problem_Management__c(); prblm = (SC_Problem_Management__c)controller.getRecord(); //Get the ID of Currently present case on vf page String csId = [SELECT Id FROM Case WHERE Id =: prblm.Case__c].Id; System.debug('testing'+ csId); prblm.Case__c= csId; if(csId != null) { //calling autofilling method autoCal(); } } //function is called from actionsupport event public void autoCal() { Id caseid = prblm.Case__c; // collecting case id from visualforce page List<Case> caseLst = [select id,Products__c,Componet__c ,Feature__c,Status,Priority,Subject,Description__c,Assignment_Group__c from Case where id=:caseid]; system.debug('Product'+ caseLst[0].Products__c); if(caseLst.isEmpty()) { return; } prblm.Products__c= caseLst[0].Products__c; prblm.Component__c = caseLst[0].Componet__c; prblm.Feature__c = caseLst[0].Feature__c; prblm.Status__c = caseLst[0].Status; prblm.Priority__c = caseLst[0].Priority; prblm.Title__c=caseLst[0].Subject; prblm.Issue_Escape__c=caseLst[0].Assignment_Group__c; prblm.Description__c= caseLst[0].Description__c; } public pagereference Save() { insert prblm; pagereference pr = new pagereference('/'+prblm.id); return pr; } }
- Snehal Gaware 15
- February 06, 2019
- Like
- 0
Need help on test class for before insert and before update trigger
Hi,
I need help in writing a test class for the following trigger.
I need help in writing a test class for the following trigger.
trigger CaseTrigger on Case (before insert,before update) { if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert)) { /* If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement and select the first one. If not then check to see if the Account on the Case has an active Entitlement. */ List<Id> contactIds = new List<Id>(); List<Id> acctIds = new List<Id>(); for (Case c: Trigger.new){ if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){ contactIds.add(c.ContactId); acctIds.add(c.AccountId); } } if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){ /* Added check for active entitlement */ List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e Where e.ContactId in:contactIds And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today]; if(entlContacts.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.ContactId!= null){ for(EntitlementContact ec:entlContacts){ if(ec.ContactId==c.ContactId){ c.EntitlementId = ec.EntitlementId; if(c.AssetId==null && ec.Entitlement.AssetId!=null) c.AssetId=ec.Entitlement.AssetId; break; } } // end for } } // end for } else{ List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId From Entitlement e Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today]; if(entls.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.AccountId!= null){ for(Entitlement e:entls){ if(e.AccountId==c.AccountId){ c.EntitlementId = e.Id; if(c.AssetId==null && e.AssetId!=null) c.AssetId=e.AssetId; break; } } // end for } } // end for } } } // end if(contactIds.isEmpty()==false) } // [Based on assignment group selection change the case owner] if(Trigger.isBefore && Trigger.isUpdate) { System.debug('entered if condition'); for(Case c : Trigger.new) { if (c.Assignment_Group__c != trigger.oldMap.get(c.Id).Assignment_Group__c){ System.debug('Updating logic'); List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue']; for(Group g : qid) { c.OwnerId = g.id; System.debug('updated'); } }} } if(Trigger.isBefore && Trigger.isUpdate) { for(Case c : Trigger.new) { if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg') { c.Group_Manager_Email__c = 'sgaware1@gmail.com'; c.Escalation_Level_2_Email__c ='sgaware1@gmail.com'; c.Escalation_Level_3_Email__c='sgaware1@gmail.com'; } } } }
- Snehal Gaware 15
- January 31, 2019
- Like
- 0
after update logic in trigger keeps on affecting because of before update
I have written a trigger on case object having before update and after update as it's events.
In Before update : Where user selects any value of "Assignment Group", based on that Case owner will get update to that particular Queue.
In After Update : Whenever Case owner changes to Queue, this event will perform auto assignment of case to queue members. Till this trigger is working as expected.
But issue occurs, when user wants to update any field on that case and save it AFTER UPDATE logic executes and case owner changed to new queue member of same queue. Assignment Group is same but case owner keeps on changing whenever user updates any value on case.
Trigger Code :
Please suggest.
In Before update : Where user selects any value of "Assignment Group", based on that Case owner will get update to that particular Queue.
In After Update : Whenever Case owner changes to Queue, this event will perform auto assignment of case to queue members. Till this trigger is working as expected.
But issue occurs, when user wants to update any field on that case and save it AFTER UPDATE logic executes and case owner changed to new queue member of same queue. Assignment Group is same but case owner keeps on changing whenever user updates any value on case.
Trigger Code :
trigger caseOwnerUpdate on Case (before insert,before update,after update) { // 1.[Based on assignment group selection change the case owner] if(Trigger.isBefore && Trigger.isUpdate) { System.debug('entered if condition'); for(Case c : Trigger.new) { System.debug('Updating logic'); List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue']; for(Group g : qid) { c.OwnerId = g.id; System.debug('updated'); } } } // 2.based on assignment group(queue) perform autoassignment of case to queue members if(Trigger.isAfter && Trigger.isUpdate) { List<Case> updateCS = new List<Case>(); Map<Id,Case> cases = new Map<Id,Case>(); for (Case cs : Trigger.new) { if(Trigger.isUpdate) { System.debug('>>>>> Owner ID: '+cs.ownerId+' Temp Owner ID: '+cs.TempOwnerId__c); if(cs.TempOwnerId__c <> null && cs.TempOwnerId__c <> '') { if(cs.OwnerId <> cs.TempOwnerId__c) { cases.put(cs.id,cs); } } } } if (cases.isEmpty()) return; for (Case cs : [SELECT OwnerId,TempOwnerId__c FROM Case WHERE id in :cases.keySet()]) { cs.OwnerId = cases.get(cs.Id).TempOwnerId__c; cs.TempOwnerId__c = 'SKIP'; //flag to stop infinite loop upon update updateCS.add(cs); } System.debug('>>>>>Update Cases: '+updateCS); // //Update last assignment for Assignment Group in batch // if (updateCS.size()>0) { try { update updateCS; } catch (Exception e){ } } } // Entitlement if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert)) { /* If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement and select the first one. If not then check to see if the Account on the Case has an active Entitlement. */ List<Id> contactIds = new List<Id>(); List<Id> acctIds = new List<Id>(); for (Case c: Trigger.new){ if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){ contactIds.add(c.ContactId); acctIds.add(c.AccountId); } } if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){ /* Added check for active entitlement */ List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e Where e.ContactId in:contactIds And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today]; if(entlContacts.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.ContactId!= null){ for(EntitlementContact ec:entlContacts){ if(ec.ContactId==c.ContactId){ c.EntitlementId = ec.EntitlementId; if(c.AssetId==null && ec.Entitlement.AssetId!=null) c.AssetId=ec.Entitlement.AssetId; break; } } // end for } } // end for } else{ List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId From Entitlement e Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today]; if(entls.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.AccountId!= null){ for(Entitlement e:entls){ if(e.AccountId==c.AccountId){ c.EntitlementId = e.Id; if(c.AssetId==null && e.AssetId!=null) c.AssetId=e.AssetId; break; } } // end for } } // end for } } } // end if(contactIds.isEmpty()==false) } // based on assignment group assign value to 3 fields if(Trigger.isBefore && Trigger.isUpdate) { for(Case c : Trigger.new) { if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg') { c.Group_Manager_Email__c = 'sgaware148@gmail.com'; c.Escalation_Level_2_Email__c ='sgaware148@gmail.com'; c.Escalation_Level_3_Email__c='sgaware148@gmail.com'; } } } }
Please suggest.
- Snehal Gaware 15
- January 28, 2019
- Like
- 0
autofilled contact name on vf page by logged in community user's name
Hi All,
I have a vf page where i have a field Contact name on case which is a lookup to contact. I want when the user logged in as community user it should autopopulate his/her name in that contact field.
vf-page:
I have a vf page where i have a field Contact name on case which is a lookup to contact. I want when the user logged in as community user it should autopopulate his/her name in that contact field.
vf-page:
<apex:page standardController="Case" extensions="AutoPopulateExample"> <apex:form id="form"> <apex:pageBlock > <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!Save}"/> <apex:commandButton value="Cancel" action="{!Cancel}"/> </apex:pageBlockButtons> <apex:actionRegion > <apex:pageBlockSection title="Basic Details" columns="2"> <apex:inputField label="Contact Name" value="{!Case.ContactId}" > <apex:actionSupport event="onchange" action="{!autoCal}" reRender="form"/> </apex:inputField> <apex:inputField label="Requestor First Name" value="{!Case.Requestor_First_Name__c}"/> <apex:inputField label="Account Name" value="{!Case.AccountId}"/> <apex:inputField label="Requestor Last Name" value="{!Case.Requestor_Last_Name__c}"/> <apex:inputField label="Status" value="{!Case.Status}"/> <apex:inputField label="Requestor Email" value="{!Case.Requester_Email__c}"/> <apex:inputField label="Subject" value="{!Case.Subject}"/> <apex:inputField label="Requestor Contact Number" value="{!Case.Requester_Contact_Number__c}"/> <apex:inputField label="Product" value="{!Case.Products__c}"/> <apex:inputField label="Business Impact" value="{!Case.Business_Impact__c}"/> <apex:inputField label="Components" value="{!Case.Componet__c}"/> <apex:inputField label="Business Urgency" value="{!Case.Business_Urgency__c}"/> <apex:inputField label="On Behalf of" value="{!Case.On_Behalf_of__c}"/> <apex:inputField label="Environment" value="{!Case.Environment__c}"/> <apex:inputField label="Description" value="{!Case.Description__c}"/> </apex:pageBlockSection> </apex:actionRegion> </apex:pageBlock> <!--<apex:commandButton value="Upload files" action="{!save}" reRender="theSection"/> --> <apex:outputPanel id="theSection" rendered="true"> <apex:pageblock > <apex:pageBlockSection title="Uploading the Attachment" collapsible="false" dir="LTR" columns="1"> <div id="upload" class="upload"> <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/> </div> </apex:pageBlockSection> </apex:pageBlock> </apex:outputPanel> </apex:form> </apex:page>
- Snehal Gaware 15
- January 24, 2019
- Like
- 0
While creating record with attchment via vf, i am getting error as missing required field body error
Hi
I am creating case through vf page where i have to attach attchment to that case while creating that case record but when i hit the save button. I am geeting error as
"Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]
Error is in expression '{!Save}' in component <apex:commandButton> in page newcase_page_for_community: Class.AutoPopulateExample.save: line 64, column 1"
Please let me know if i am doing something wrong.
VF page
Apex Controller :
Please suggest.
I am creating case through vf page where i have to attach attchment to that case while creating that case record but when i hit the save button. I am geeting error as
"Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]
Error is in expression '{!Save}' in component <apex:commandButton> in page newcase_page_for_community: Class.AutoPopulateExample.save: line 64, column 1"
Please let me know if i am doing something wrong.
VF page
<apex:page standardController="Case" extensions="AutoPopulateExample"> <apex:form id="form"> <apex:pageBlock > <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!Save}"/> <apex:commandButton value="Cancel" action="{!Cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Basic Details" columns="2"> <apex:inputField label="Contact Name" value="{!Case.ContactId}" > <apex:actionSupport event="onchange" action="{!autoCal}" reRender="form"/> </apex:inputField> <apex:inputField label="Requestor First Name" value="{!Case.Requestor_First_Name__c}"/> <apex:inputField label="Account Name" value="{!Case.AccountId}"/> <apex:inputField label="Requestor Last Name" value="{!Case.Requestor_Last_Name__c}"/> <apex:inputField label="Status" value="{!Case.Status}"/> <apex:inputField label="Requestor Email" value="{!Case.Requester_Email__c}"/> <apex:inputField label="Subject" value="{!Case.Subject}"/> <apex:inputField label="Requestor Contact Number" value="{!Case.Requester_Contact_Number__c}"/> <apex:inputField label="Product" value="{!Case.Products__c}"/> <apex:inputField label="Business Impact" value="{!Case.Business_Impact__c}"/> <apex:inputField label="Components" value="{!Case.Componet__c}"/> <apex:inputField label="Business Urgency" value="{!Case.Business_Urgency__c}"/> <apex:inputField label="On Behalf of" value="{!Case.On_Behalf_of__c}"/> <apex:inputField label="Environment" value="{!Case.Environment__c}"/> <apex:inputField label="Description" value="{!Case.Description__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <apex:form > <apex:outputPanel id="theSection" rendered="true"> <apex:pageblock > <apex:pageBlockSection title="Uploading the Attachment" collapsible="false" dir="LTR" columns="1"> <div id="upload" class="upload"> <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/> </div> </apex:pageBlockSection> </apex:pageBlock> </apex:outputPanel> </apex:form> </apex:page>
Apex Controller :
public class AutoPopulateExample { public string fileName{get;set;} public Blob fileBody{get;set;} public Contact con{get;set;} public Case caseObject{get;set;} public Attachment attachmentObject { get { if (attachmentObject == null) attachmentObject = new Attachment(); return attachmentObject ; } set; } public ApexPages.StandardController stdCntrlr {get; set;} public AutoPopulateExample(ApexPages.StandardController controller) { con = new Contact(); caseObject = new case(); caseObject = (Case)controller.getRecord(); attachmentObject = new Attachment(); } //function is called from actionsupport event public void autoCal() { Id conid = caseObject.ContactId; // collecting contact id from visualforce page List<Contact> conLst = [select id,AccountId,FirstName,LastName,Email,Phone from contact where id=:conid]; if(conLst.isEmpty()) { return; } caseObject.Requestor_First_Name__c = conLst[0].FirstName; caseObject.AccountId = conLst[0].AccountId; caseObject.Requestor_Last_Name__c = conLst[0].LastName; caseObject.Requester_Email__c = conLst[0].Email; caseObject.Requester_Contact_Number__c = conLst[0].Phone; } public PageReference save() { // Save the Case insert caseObject; // Save the Attachment using the Case id as the parent Id System.debug('@@@@@fileBody'+fileBody); attachmentObject = new Attachment(); Integer i=0; attachmentObject .clear(); attachmentObject.Body = fileBody; attachmentObject.Name = 'Logo_'+caseObject.id+'.jpeg' ; attachmentObject.ParentId = caseObject.id; insert attachmentObject; pagereference pr = new pagereference('/'+caseObject.id); return pr; } }
Please suggest.
- Snehal Gaware 15
- January 23, 2019
- Like
- 0
restrict access to standard button “new case” button on list view to particular profile
1.I have created a custom button which should be accessed by only 1 profile
2.I want restrict access to standard button "new case" button on list view to same profile
Could you please advice how to achieve this?
2.I want restrict access to standard button "new case" button on list view to same profile
Could you please advice how to achieve this?
- Snehal Gaware 15
- January 13, 2019
- Like
- 0
auto populate contact's field value on case's fields before saving the record
I have contact name field on case, requirement is fields related to contact (i.e.first Name, last name, email, phone etc.) should autopopulate before saving the record.
- Snehal Gaware 15
- January 11, 2019
- Like
- 0
Visibility of cases for Community end users after it is assigned to queue using auto assignment rules.
We have created a community for end users to be able to add, update and see their own cases.
The end user is able to create their cases just fine. I have assignment rule where when case is created and it is assigned to Tech support queue. after queue is assigned as owner of the case, the end user looses visibility of it.
End user should able to atleast see cases generated by him/her.
Does anyone have experience with communities and cases visbility?
The end user is able to create their cases just fine. I have assignment rule where when case is created and it is assigned to Tech support queue. after queue is assigned as owner of the case, the end user looses visibility of it.
End user should able to atleast see cases generated by him/her.
Does anyone have experience with communities and cases visbility?
- Snehal Gaware 15
- January 08, 2019
- Like
- 0
i want to change case owner to a queue
Hi Team,
As we can not create lookup on queues, i have created picklist field named as assignment group where i have given all queues name.
Now i need to change case owner on case based on picklist value selection. like if assignment group is Tech support, i need to assign Tech support queue to case owner field.
Could you please suggest me how to achieve this?
Regards,
Snehal
As we can not create lookup on queues, i have created picklist field named as assignment group where i have given all queues name.
Now i need to change case owner on case based on picklist value selection. like if assignment group is Tech support, i need to assign Tech support queue to case owner field.
Could you please suggest me how to achieve this?
Regards,
Snehal
- Snehal Gaware 15
- January 04, 2019
- Like
- 0
I need to create a lookup for queues on case object. Is there any workaround for this requirement
I need to create a lookup for queues on case object. Is there any workaround for this requirement
- Snehal Gaware 15
- December 21, 2018
- Like
- 0
Based on account(lookup) selection on case, need to display values in picklist field
Hi
I have a requirement where I need to show values in picklist based on specific Account selection.
We have lookup field of Account on Case, where if user selects Account A , he will be only allowed to select value1,value3,value4 from product picklist.
if user selectes Account B, he will be only allowed to select value2,value5,value8 from product picklist
I have a requirement where I need to show values in picklist based on specific Account selection.
We have lookup field of Account on Case, where if user selects Account A , he will be only allowed to select value1,value3,value4 from product picklist.
if user selectes Account B, he will be only allowed to select value2,value5,value8 from product picklist
- Snehal Gaware 15
- December 20, 2018
- Like
- 0
test class coverage is showing constant is 53 only.
Hi, i need help on test class of below trigger.
trigger CaseTrigger on Case (before insert,before update, after update) { if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert)) { List<Id> contactIds = new List<Id>(); List<Id> acctIds = new List<Id>(); for (Case c: Trigger.new){ if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){ contactIds.add(c.ContactId); acctIds.add(c.AccountId); } } if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){ /* Added check for active entitlement */ List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e Where e.ContactId in:contactIds And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today]; if(entlContacts.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.ContactId!= null){ for(EntitlementContact ec:entlContacts){ if(ec.ContactId==c.ContactId){ c.EntitlementId = ec.EntitlementId; if(c.AssetId==null && ec.Entitlement.AssetId!=null) c.AssetId=ec.Entitlement.AssetId; break; } } // end for entitlement } } // end for case } else{ List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId From Entitlement e Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today]; if(entls.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.AccountId!= null){ for(Entitlement e:entls){ if(e.AccountId==c.AccountId){ c.EntitlementId = e.Id; if(c.AssetId==null && e.AssetId!=null) c.AssetId=e.AssetId; break; } } // end for } } // end for } } } // end if(contactIds.isEmpty()==false) } if(Trigger.isBefore && Trigger.isUpdate) { System.debug('entered if condition'); for(Case c : Trigger.new) { if (c.Assignment_Group__c != trigger.oldMap.get(c.Id).Assignment_Group__c){ System.debug('Updating logic'); List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue']; for(Group g : qid) { c.OwnerId = g.id; System.debug('updated'); } }} } if(Trigger.isBefore && Trigger.isUpdate) { for(Case c : Trigger.new) { if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg') { c.Group_Manager_Email__c = 'sargware@gmail.com'; c.Escalation_Level_2_Email__c ='sargware@gmail.com'; c.Escalation_Level_3_Email__c='sargware@gmail.com'; } } } if(Trigger.isBefore && Trigger.isUpdate) { for(Case c : Trigger.new) { if(c.Internal_Impact__c == 'Low' && c.Internal_Urgency__c=='Low') { c.Priority='Planning'; } if(c.Internal_Impact__c == 'High' && c.Internal_Urgency__c=='High') { c.Priority='Critical'; } if(c.Status=='Pending User' || c.Status=='Pending Vendor') { c.IsStopped = True; } } } if((Trigger.isAfter && Trigger.isUpdate)) { Set<Id> Ids = new Set<Id>(); Set<Id> IdR = new Set<Id>(); Set<Id> IdC = new Set<Id>(); List<SC_Problem_Case_Link__c> scprblm = new List<SC_Problem_Case_Link__c>(); List<SC_Problem_Case_Link__c> scprblmo = new List<SC_Problem_Case_Link__c>(); List<SC_Problem_Case_Link__c> scprblmc = new List<SC_Problem_Case_Link__c>(); for (Case cs: Trigger.new) { Case oldLead = Trigger.oldMap.get(cs.Id); if (cs.Status == 'Tested' && Trigger.oldMap.get(oldLead .Id).Status=='Ready for Testing') { Ids.add(cs.Id); } if (cs.Status == 'ReOpen') { IdR.add(cs.Id); } if (cs.Status == 'Closed') { IdC.add(cs.Id); } } for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Ready for Testing' AND Case__c in :Ids]) { if (rateSheet.Status__c != 'Tested') { rateSheet.Status__c = 'Tested'; //rateSheet.Case__c.Status= 'Awaiting Deployment'; scprblm.add(rateSheet); } } if (!scprblm.isEmpty()) { update scprblm; } for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdR]) { // List<SC_Problem_Case_Link__c> accts = [Select Id, Status__c from SC_Problem_Case_Link__c where Id in : Trigger.old]; if (rateSheet.Status__c != 'Open') { rateSheet.Status__c = 'Open'; scprblmo.add(rateSheet); } } if (!scprblmo.isEmpty()) { update scprblmo; } for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdC]) { if (rateSheet.Status__c != 'Closed') { rateSheet.Status__c = 'Closed'; scprblmc.add(rateSheet); } } if (!scprblmc.isEmpty()) { update scprblmc; } } }test class :
@isTest public class CaseTrigger_Test { @isTest static void caseTriggerTest(){ Account acc=new Account(); acc.name = 'Acc Name'; insert acc; Contact con= new Contact(); con.lastname = 'con lName'; con.AccountId= acc.Id; insert con; Entitlement ent = new Entitlement(Name='test2', AccountId=acc.Id, StartDate=Date.valueof(System.now().addDays(-10)), EndDate=Date.valueof(System.now().addYears(3))); insert ent; EntitlementContact ec = new EntitlementContact(EntitlementId=ent.Id, ContactId=con.Id); insert ec; case c=new case(); c.AccountId = acc.Id; c.ContactId = con.Id; c.Assignment_Group__c = 'Tech Support'; insert c; c.Assignment_Group__c = 'GD-DB'; update c; } @isTest static void caseTriggerTest1(){ Account acc=new Account(); acc.name = 'Acc Name'; insert acc; Contact con= new Contact(); con.lastname = 'con lName'; con.AccountId= acc.Id; insert con; Entitlement ent = new Entitlement(Name='test2', AccountId=acc.Id, StartDate=Date.valueof(System.now().addDays(-10)), EndDate=Date.valueof(System.now().addYears(3))); insert ent; case c=new case(); c.AccountId = acc.Id; c.ContactId = con.Id; insert c; } @isTest static void caseTriggerTest2(){ Account acc=new Account(); acc.name = 'Acc Name'; insert acc; Contact con= new Contact(); con.lastname = 'con lName'; con.AccountId= acc.Id; insert con; Entitlement ent = new Entitlement(Name='test2', AccountId=acc.Id, StartDate=Date.valueof(System.now().addDays(-10)), EndDate=Date.valueof(System.now().addYears(3))); insert ent; case c=new case(); c.AccountId = acc.Id; c.ContactId = con.Id; c.Internal_Impact__c = 'Low'; c.Priority = 'Medium'; insert c; SC_Problem_Management__c sc=new SC_Problem_Management__c(); sc.Products__c= 'AutoClass'; sc.Impact__c='Critical'; sc.Urgency__c='Critical'; sc.Priority__c='Critical'; insert sc; SC_Problem_Case_Link__c scpl=new SC_Problem_Case_Link__c(); scpl.Case__c=c.Id; scpl.SC_Problem_Management__c= sc.Id; scpl.Status__c='Open'; insert scpl; if(scpl.Status__c!='Resolved'){ scpl.Status__c='Resolved';} update scpl; c.Priority = 'Planning'; update c; } }
- Snehal Gaware 15
- February 27, 2019
- Like
- 0
test class for after update trigger on case
Hi team,
I need help in writting test class for after update trigger on case.
Thanks in advance. Any help will be appreciated.
I need help in writting test class for after update trigger on case.
trigger caseOwnerUpdate on Case (after update) { List<Case> updateCS = new List<Case>(); Map<Id,Case> cases = new Map<Id,Case>(); for (Case cs : Trigger.new) { if(Trigger.isUpdate) { System.debug('>>>>> Owner ID: '+cs.ownerId+' Temp Owner ID: '+cs.TempOwnerId__c); if(cs.TempOwnerId__c <> null && cs.TempOwnerId__c <> '' && cs.OwnerId != trigger.oldMap.Get(cs.Id).OwnerId) { system.debug('pleasecheck'+trigger.oldMap.Get(cs.Id).OwnerId); if(cs.OwnerId <> cs.TempOwnerId__c) { cases.put(cs.id,cs); } } } } if (cases.isEmpty()) return; for (Case cs : [SELECT OwnerId,TempOwnerId__c FROM Case WHERE id in :cases.keySet()]) { cs.OwnerId = cases.get(cs.Id).TempOwnerId__c; system.debug('pleasecheck2'+ cs.OwnerId); cs.TempOwnerId__c = 'SKIP'; //flag to stop infinite loop upon update updateCS.add(cs); } System.debug('>>>>>Update Cases: '+updateCS); // //Update last assignment for Assignment Group in batch // if (updateCS.size()>0) { try { update updateCS; } catch (Exception e){ } } }
Thanks in advance. Any help will be appreciated.
- Snehal Gaware 15
- February 27, 2019
- Like
- 0
test class for apex class.. need help
Hi,
I need help in writting test class for following class.
Thanks in advance. any help will be appreciated.
I need help in writting test class for following class.
public class Populate { public Case cs{get;set;} public SC_Problem_Management__c prblm{get;set;} public ApexPages.StandardController stdCntrlr {get; set;} public Populate(ApexPages.StandardController controller) { cs = new Case(); prblm = new SC_Problem_Management__c(); prblm = (SC_Problem_Management__c)controller.getRecord(); //Get the ID of Currently present case on vf page String csId = [SELECT Id FROM Case WHERE Id =: prblm.Case__c].Id; System.debug('testing'+ csId); prblm.Case__c= csId; if(csId != null) { //calling autofilling method autoCal(); } } //function is called from actionsupport event public void autoCal() { Id caseid = prblm.Case__c; // collecting case id from visualforce page if(caseid!=null){ List<Case> caseLst = [select id,Products__c,Componet__c ,Feature__c,Status,Priority,Subject,Description__c,Assignment_Group__c from Case where id=:caseid]; system.debug('Product'+ caseLst[0].Products__c); if(!caseLst.isEmpty()) { prblm.Products__c= caseLst[0].Products__c; prblm.Component__c = caseLst[0].Componet__c; prblm.Feature__c = caseLst[0].Feature__c; prblm.Status__c = caseLst[0].Status; prblm.Priority__c = caseLst[0].Priority; prblm.Title__c=caseLst[0].Subject; prblm.Issue_Escape__c=caseLst[0].Assignment_Group__c; prblm.Description__c= caseLst[0].Description__c; } } } public pagereference Save() { insert prblm; pagereference pr = new pagereference('/'+prblm.id); System.debug('pagereference/////'+pr); return pr; } }
Thanks in advance. any help will be appreciated.
- Snehal Gaware 15
- February 27, 2019
- Like
- 0
not able to create record through vf page on object tab. getting error as "List has no rows for assignment to SObject ".
Hi i have created vf page and controller to override new button of custom object (Problem). So whenever i am able to create problem through case and it is working as expected. but when i am creating problem though it's tab i am getting error as : "List has no rows for assignment to SObject " . Please suggest.
controller :
controller :
public class Populate { public Case cs{get;set;} public SC_Problem_Management__c prblm{get;set;} public ApexPages.StandardController stdCntrlr {get; set;} public Populate(ApexPages.StandardController controller) { cs = new Case(); prblm = new SC_Problem_Management__c(); prblm = (SC_Problem_Management__c)controller.getRecord(); //Get the ID of Currently present case on vf page String csId = [SELECT Id FROM Case WHERE Id =: prblm.Case__c].Id; System.debug('testing'+ csId); prblm.Case__c= csId; if(csId != null) { //calling autofilling method autoCal(); } } //function is called from actionsupport event public void autoCal() { Id caseid = prblm.Case__c; // collecting case id from visualforce page List<Case> caseLst = [select id,Products__c,Componet__c ,Feature__c,Status,Priority,Subject,Description__c,Assignment_Group__c from Case where id=:caseid]; system.debug('Product'+ caseLst[0].Products__c); if(caseLst.isEmpty()) { return; } prblm.Products__c= caseLst[0].Products__c; prblm.Component__c = caseLst[0].Componet__c; prblm.Feature__c = caseLst[0].Feature__c; prblm.Status__c = caseLst[0].Status; prblm.Priority__c = caseLst[0].Priority; prblm.Title__c=caseLst[0].Subject; prblm.Issue_Escape__c=caseLst[0].Assignment_Group__c; prblm.Description__c= caseLst[0].Description__c; } public pagereference Save() { insert prblm; pagereference pr = new pagereference('/'+prblm.id); return pr; } }
- Snehal Gaware 15
- February 06, 2019
- Like
- 0
Need help on test class for before insert and before update trigger
Hi,
I need help in writing a test class for the following trigger.
I need help in writing a test class for the following trigger.
trigger CaseTrigger on Case (before insert,before update) { if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert)) { /* If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement and select the first one. If not then check to see if the Account on the Case has an active Entitlement. */ List<Id> contactIds = new List<Id>(); List<Id> acctIds = new List<Id>(); for (Case c: Trigger.new){ if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){ contactIds.add(c.ContactId); acctIds.add(c.AccountId); } } if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){ /* Added check for active entitlement */ List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e Where e.ContactId in:contactIds And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today]; if(entlContacts.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.ContactId!= null){ for(EntitlementContact ec:entlContacts){ if(ec.ContactId==c.ContactId){ c.EntitlementId = ec.EntitlementId; if(c.AssetId==null && ec.Entitlement.AssetId!=null) c.AssetId=ec.Entitlement.AssetId; break; } } // end for } } // end for } else{ List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId From Entitlement e Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today]; if(entls.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.AccountId!= null){ for(Entitlement e:entls){ if(e.AccountId==c.AccountId){ c.EntitlementId = e.Id; if(c.AssetId==null && e.AssetId!=null) c.AssetId=e.AssetId; break; } } // end for } } // end for } } } // end if(contactIds.isEmpty()==false) } // [Based on assignment group selection change the case owner] if(Trigger.isBefore && Trigger.isUpdate) { System.debug('entered if condition'); for(Case c : Trigger.new) { if (c.Assignment_Group__c != trigger.oldMap.get(c.Id).Assignment_Group__c){ System.debug('Updating logic'); List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue']; for(Group g : qid) { c.OwnerId = g.id; System.debug('updated'); } }} } if(Trigger.isBefore && Trigger.isUpdate) { for(Case c : Trigger.new) { if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg') { c.Group_Manager_Email__c = 'sgaware1@gmail.com'; c.Escalation_Level_2_Email__c ='sgaware1@gmail.com'; c.Escalation_Level_3_Email__c='sgaware1@gmail.com'; } } } }
- Snehal Gaware 15
- January 31, 2019
- Like
- 0
after update logic in trigger keeps on affecting because of before update
I have written a trigger on case object having before update and after update as it's events.
In Before update : Where user selects any value of "Assignment Group", based on that Case owner will get update to that particular Queue.
In After Update : Whenever Case owner changes to Queue, this event will perform auto assignment of case to queue members. Till this trigger is working as expected.
But issue occurs, when user wants to update any field on that case and save it AFTER UPDATE logic executes and case owner changed to new queue member of same queue. Assignment Group is same but case owner keeps on changing whenever user updates any value on case.
Trigger Code :
Please suggest.
In Before update : Where user selects any value of "Assignment Group", based on that Case owner will get update to that particular Queue.
In After Update : Whenever Case owner changes to Queue, this event will perform auto assignment of case to queue members. Till this trigger is working as expected.
But issue occurs, when user wants to update any field on that case and save it AFTER UPDATE logic executes and case owner changed to new queue member of same queue. Assignment Group is same but case owner keeps on changing whenever user updates any value on case.
Trigger Code :
trigger caseOwnerUpdate on Case (before insert,before update,after update) { // 1.[Based on assignment group selection change the case owner] if(Trigger.isBefore && Trigger.isUpdate) { System.debug('entered if condition'); for(Case c : Trigger.new) { System.debug('Updating logic'); List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue']; for(Group g : qid) { c.OwnerId = g.id; System.debug('updated'); } } } // 2.based on assignment group(queue) perform autoassignment of case to queue members if(Trigger.isAfter && Trigger.isUpdate) { List<Case> updateCS = new List<Case>(); Map<Id,Case> cases = new Map<Id,Case>(); for (Case cs : Trigger.new) { if(Trigger.isUpdate) { System.debug('>>>>> Owner ID: '+cs.ownerId+' Temp Owner ID: '+cs.TempOwnerId__c); if(cs.TempOwnerId__c <> null && cs.TempOwnerId__c <> '') { if(cs.OwnerId <> cs.TempOwnerId__c) { cases.put(cs.id,cs); } } } } if (cases.isEmpty()) return; for (Case cs : [SELECT OwnerId,TempOwnerId__c FROM Case WHERE id in :cases.keySet()]) { cs.OwnerId = cases.get(cs.Id).TempOwnerId__c; cs.TempOwnerId__c = 'SKIP'; //flag to stop infinite loop upon update updateCS.add(cs); } System.debug('>>>>>Update Cases: '+updateCS); // //Update last assignment for Assignment Group in batch // if (updateCS.size()>0) { try { update updateCS; } catch (Exception e){ } } } // Entitlement if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert)) { /* If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement and select the first one. If not then check to see if the Account on the Case has an active Entitlement. */ List<Id> contactIds = new List<Id>(); List<Id> acctIds = new List<Id>(); for (Case c: Trigger.new){ if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){ contactIds.add(c.ContactId); acctIds.add(c.AccountId); } } if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){ /* Added check for active entitlement */ List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e Where e.ContactId in:contactIds And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today]; if(entlContacts.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.ContactId!= null){ for(EntitlementContact ec:entlContacts){ if(ec.ContactId==c.ContactId){ c.EntitlementId = ec.EntitlementId; if(c.AssetId==null && ec.Entitlement.AssetId!=null) c.AssetId=ec.Entitlement.AssetId; break; } } // end for } } // end for } else{ List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId From Entitlement e Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today]; if(entls.isEmpty()==false){ for(Case c: Trigger.new){ if(c.EntitlementId == null && c.AccountId!= null){ for(Entitlement e:entls){ if(e.AccountId==c.AccountId){ c.EntitlementId = e.Id; if(c.AssetId==null && e.AssetId!=null) c.AssetId=e.AssetId; break; } } // end for } } // end for } } } // end if(contactIds.isEmpty()==false) } // based on assignment group assign value to 3 fields if(Trigger.isBefore && Trigger.isUpdate) { for(Case c : Trigger.new) { if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg') { c.Group_Manager_Email__c = 'sgaware148@gmail.com'; c.Escalation_Level_2_Email__c ='sgaware148@gmail.com'; c.Escalation_Level_3_Email__c='sgaware148@gmail.com'; } } } }
Please suggest.
- Snehal Gaware 15
- January 28, 2019
- Like
- 0
autofilled contact name on vf page by logged in community user's name
Hi All,
I have a vf page where i have a field Contact name on case which is a lookup to contact. I want when the user logged in as community user it should autopopulate his/her name in that contact field.
vf-page:
I have a vf page where i have a field Contact name on case which is a lookup to contact. I want when the user logged in as community user it should autopopulate his/her name in that contact field.
vf-page:
<apex:page standardController="Case" extensions="AutoPopulateExample"> <apex:form id="form"> <apex:pageBlock > <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!Save}"/> <apex:commandButton value="Cancel" action="{!Cancel}"/> </apex:pageBlockButtons> <apex:actionRegion > <apex:pageBlockSection title="Basic Details" columns="2"> <apex:inputField label="Contact Name" value="{!Case.ContactId}" > <apex:actionSupport event="onchange" action="{!autoCal}" reRender="form"/> </apex:inputField> <apex:inputField label="Requestor First Name" value="{!Case.Requestor_First_Name__c}"/> <apex:inputField label="Account Name" value="{!Case.AccountId}"/> <apex:inputField label="Requestor Last Name" value="{!Case.Requestor_Last_Name__c}"/> <apex:inputField label="Status" value="{!Case.Status}"/> <apex:inputField label="Requestor Email" value="{!Case.Requester_Email__c}"/> <apex:inputField label="Subject" value="{!Case.Subject}"/> <apex:inputField label="Requestor Contact Number" value="{!Case.Requester_Contact_Number__c}"/> <apex:inputField label="Product" value="{!Case.Products__c}"/> <apex:inputField label="Business Impact" value="{!Case.Business_Impact__c}"/> <apex:inputField label="Components" value="{!Case.Componet__c}"/> <apex:inputField label="Business Urgency" value="{!Case.Business_Urgency__c}"/> <apex:inputField label="On Behalf of" value="{!Case.On_Behalf_of__c}"/> <apex:inputField label="Environment" value="{!Case.Environment__c}"/> <apex:inputField label="Description" value="{!Case.Description__c}"/> </apex:pageBlockSection> </apex:actionRegion> </apex:pageBlock> <!--<apex:commandButton value="Upload files" action="{!save}" reRender="theSection"/> --> <apex:outputPanel id="theSection" rendered="true"> <apex:pageblock > <apex:pageBlockSection title="Uploading the Attachment" collapsible="false" dir="LTR" columns="1"> <div id="upload" class="upload"> <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/> </div> </apex:pageBlockSection> </apex:pageBlock> </apex:outputPanel> </apex:form> </apex:page>
- Snehal Gaware 15
- January 24, 2019
- Like
- 0
While creating record with attchment via vf, i am getting error as missing required field body error
Hi
I am creating case through vf page where i have to attach attchment to that case while creating that case record but when i hit the save button. I am geeting error as
"Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]
Error is in expression '{!Save}' in component <apex:commandButton> in page newcase_page_for_community: Class.AutoPopulateExample.save: line 64, column 1"
Please let me know if i am doing something wrong.
VF page
Apex Controller :
Please suggest.
I am creating case through vf page where i have to attach attchment to that case while creating that case record but when i hit the save button. I am geeting error as
"Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]
Error is in expression '{!Save}' in component <apex:commandButton> in page newcase_page_for_community: Class.AutoPopulateExample.save: line 64, column 1"
Please let me know if i am doing something wrong.
VF page
<apex:page standardController="Case" extensions="AutoPopulateExample"> <apex:form id="form"> <apex:pageBlock > <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!Save}"/> <apex:commandButton value="Cancel" action="{!Cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Basic Details" columns="2"> <apex:inputField label="Contact Name" value="{!Case.ContactId}" > <apex:actionSupport event="onchange" action="{!autoCal}" reRender="form"/> </apex:inputField> <apex:inputField label="Requestor First Name" value="{!Case.Requestor_First_Name__c}"/> <apex:inputField label="Account Name" value="{!Case.AccountId}"/> <apex:inputField label="Requestor Last Name" value="{!Case.Requestor_Last_Name__c}"/> <apex:inputField label="Status" value="{!Case.Status}"/> <apex:inputField label="Requestor Email" value="{!Case.Requester_Email__c}"/> <apex:inputField label="Subject" value="{!Case.Subject}"/> <apex:inputField label="Requestor Contact Number" value="{!Case.Requester_Contact_Number__c}"/> <apex:inputField label="Product" value="{!Case.Products__c}"/> <apex:inputField label="Business Impact" value="{!Case.Business_Impact__c}"/> <apex:inputField label="Components" value="{!Case.Componet__c}"/> <apex:inputField label="Business Urgency" value="{!Case.Business_Urgency__c}"/> <apex:inputField label="On Behalf of" value="{!Case.On_Behalf_of__c}"/> <apex:inputField label="Environment" value="{!Case.Environment__c}"/> <apex:inputField label="Description" value="{!Case.Description__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <apex:form > <apex:outputPanel id="theSection" rendered="true"> <apex:pageblock > <apex:pageBlockSection title="Uploading the Attachment" collapsible="false" dir="LTR" columns="1"> <div id="upload" class="upload"> <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/> </div> </apex:pageBlockSection> </apex:pageBlock> </apex:outputPanel> </apex:form> </apex:page>
Apex Controller :
public class AutoPopulateExample { public string fileName{get;set;} public Blob fileBody{get;set;} public Contact con{get;set;} public Case caseObject{get;set;} public Attachment attachmentObject { get { if (attachmentObject == null) attachmentObject = new Attachment(); return attachmentObject ; } set; } public ApexPages.StandardController stdCntrlr {get; set;} public AutoPopulateExample(ApexPages.StandardController controller) { con = new Contact(); caseObject = new case(); caseObject = (Case)controller.getRecord(); attachmentObject = new Attachment(); } //function is called from actionsupport event public void autoCal() { Id conid = caseObject.ContactId; // collecting contact id from visualforce page List<Contact> conLst = [select id,AccountId,FirstName,LastName,Email,Phone from contact where id=:conid]; if(conLst.isEmpty()) { return; } caseObject.Requestor_First_Name__c = conLst[0].FirstName; caseObject.AccountId = conLst[0].AccountId; caseObject.Requestor_Last_Name__c = conLst[0].LastName; caseObject.Requester_Email__c = conLst[0].Email; caseObject.Requester_Contact_Number__c = conLst[0].Phone; } public PageReference save() { // Save the Case insert caseObject; // Save the Attachment using the Case id as the parent Id System.debug('@@@@@fileBody'+fileBody); attachmentObject = new Attachment(); Integer i=0; attachmentObject .clear(); attachmentObject.Body = fileBody; attachmentObject.Name = 'Logo_'+caseObject.id+'.jpeg' ; attachmentObject.ParentId = caseObject.id; insert attachmentObject; pagereference pr = new pagereference('/'+caseObject.id); return pr; } }
Please suggest.
- Snehal Gaware 15
- January 23, 2019
- Like
- 0