• BennettTran
  • NEWBIE
  • 50 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 9
    Replies
Hello,

I have the following trigger but I only want the trigger to fire when the parent case field is changed.  Can someone please assist?  Thanks in advanced.





trigger UpdateChildCase on Case (before update) {

List<Id> parentCaseIds = new List<Id>();

RecordType rt = [select id from RecordType where DeveloperName='Integration' and SobjectType='Case'];

for(Case c : Trigger.new)
{
if(c.RecordTypeId==rt.id)
{
  parentCaseIds.add(c.ParentId);
}
}

//Query the parentcase Values,yoou need to query all fields which you want to be populated in yiur child case
Map<Id,Case> caseMap =new Map<Id,Case> ([select id, Average_visits_per_week__c, Biller_attending_training__c, Billing_company__c, Billing_contact_email__c, Billing_contact_first_name__c, Billing_Contact_Last_Name__c, Billing_Contact_Phone__c,
Billing_Integration_Choice__c, Billing_Integration_required__c, Clinic_Business_Hours__c, Clinic_ID__c, Clinic_Implementation_Contact_s__c, Clinic_Name__c, Clinic_Owner__c,
Clinic_Primary_Contact_s__c, Company_ID__c, Computer_Equipment__c, ContactId, Current_Billing_Method__c, Description, Document_Existing_Patients__c, eDoc_Only__c, EMR_or_Paper__c, Future_Billing_Software__c, Imports_Required__c,
Import_Contact_Email__c, Import_Contact_Name__c, Import_Type__c, Integration_Comments__c, Member_Implementation_Plan__c, Multiple_TaxIDs__c, Opportunity__c, Order_Confirmation_Date__c, Origin, Other_Decision_Maker_s__c, Preferred_Go_Live_Date__c,
Previous_Billing_Software__c, Previous_EMR_Software__c, Priority, PTA_Cosign_Required__c, Reason, Specialties__c, Startup_or_Existing_Clinic__c from Case where Id in:parentCaseIds]);

//populate the child case with related Parentcase values.

for(Case c : Trigger.new)
{
if(!caseMap.IsEmpty())
{
  c.Origin = caseMap.get(c.ParentId).Origin;
  c.Subject = caseMap.get(c.ParentId).Subject;
  c.Average_visits_per_week__c = casemap.get(c.ParentId).Average_visits_per_week__c;
  c.Biller_attending_training__c = caseMap.get(c.ParentId).Biller_attending_training__c;
  c.Billing_contact_email__c = caseMap.get(c.ParentId).Billing_contact_email__c;
  c.Billing_contact_first_name__c = caseMap.get(c.ParentId).Billing_contact_first_name__c;
  c.Billing_Contact_Last_Name__c = caseMap.get(c.ParentId).Billing_Contact_Last_Name__c;
  c.Billing_Contact_Phone__c = caseMap.get(c.ParentId).Billing_Contact_Phone__c;
  c.Billing_Integration_Choice__c = caseMap.get(c.ParentId).Billing_Integration_Choice__c;
  c.Billing_Integration_required__c = caseMap.get(c.ParentId).Billing_Integration_required__c;
  c.Clinic_Business_Hours__c = caseMap.get(c.ParentId).Clinic_Business_Hours__c;
}
}
}
Hello,

I am new to APEX and was hoping someone could help me.  I am looking to create a class for a button on the case object.  I would like the button to be placed on child cases and retrieve data from certain fields from the parent case.  

I recently created a class for a button on the parent case that will create new child cases and pre-populate certain fields but am not sure how to reverse-engineer my solution for the use case described above.

Can someone please help me write this class or help me write the foundation?

Thanks in advanced.

Hello,

 

I am fairly new to APEX and have recently ran into an error when trying to do a mass upload using dataloader.  I have found that the error is because I have an IF statement within a FOR loop and was hoping someone could help me take the IF statement out with different logic?  My code is below and I have highlighted the IF statement in red that is looping through.  Thanks in advance.

 

 

trigger ImplementationCaseforIntegrationProducts on Opportunity (after insert, after update) {

string recordtype = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Implementation').getRecordTypeId();
List<Case> cases = new List<Case>();
List<Task> tasksList = new List<Task>();
for (Opportunity opp: Trigger.New){
case newcase= new case();
if(opp.AccountId != null){
Account a = [select id,name,Closed__c,ImplementationCaseCreated__c,Implementation_Specialist__c from Account where id =: opp.AccountId limit 1]; //This line more than enough to check in common, because if account id in opportunity is not null means only one value going to be there.

if((trigger.isInsert && (opp.StageName.toLowerCase().equals('closed won'))&&(opp.Type.toLowerCase().equals('adjustment'))&& opp.Integration_Product_Attached__c == True)||
(trigger.isUpdate && (opp.StageName != Trigger.oldMap.get(opp.Id).StageName && opp.StageName.toLowerCase().equals('closed won'))&&(opp.Type.toLowerCase().equals('adjustment')) && opp.Integration_Product_Attached__c == True))
{
if ((a.Closed__c == TRUE && a.implementationcasecreated__c == TRUE) || (a.ImplementationCaseCreated__c == False)){
newcase.AccountId=opp.AccountId;
newcase.Opportunity__c=opp.Id;
newcase.Subject='New Implementation case for '+opp.Account_Name__c;
newcase.Status='New';
newcase.Origin='Sign Up Form';
newcase.Priority='Medium';
newcase.RecordTypeId=recordtype;
newcase.Billing_Email__c = opp.Billing_Email__c;
newcase.ContactID = opp.PrimaryContactID__c;
cases.add(newcase);
}
else{
Task t = new Task(ownerId = a.Implementation_Specialist__c, Subject = 'Integration Sale', status = 'Not Started',
Priority = 'High', whatID = opp.Accountid, ActivityDate = Date.Today()); //You can change values accordingly
tasksList.add(t);
}
}
}
}

if(cases.size() > 0){
insert cases;
}
if(tasksList.size() > 0){
insert tasksList;
}
}

Hi All,

 

I am new to apex coding but took a shot at writing an opportunity trigger to create a case based off of certain criteria.  The issue I am running into is that a requirement of the trigger is to create a task instead of a case if a field on the associated account called "Closed"(checkbox) is not checked.  I am not sure how to code that logic, currently I have the trigger creating a case if the field "Closed" is checked but not sure how to do it the other way around.  The trigger I have written is below and any help would be greatly appreciated.

 

trigger ImplementationCaseforIntegrationProducts on Opportunity (after insert, after update) {
string recordtype = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Implementation').getRecordTypeId();
/* List<Task> tasks = new List<Task>();*/
List<Case> cases = new List<Case>();
for (Opportunity opp: Trigger.New)
{ case newcase= new case();
if((trigger.isInsert && (opp.StageName.toLowerCase().equals('closed won'))&&((opp.Type.toLowerCase().equals('adjustment'))|| (opp.Type.toLowerCase().equals('additional sales')))&& opp.Integration_Product_Attached__c == True)||
(trigger.isUpdate && (opp.StageName != Trigger.oldMap.get(opp.Id).StageName && opp.StageName.toLowerCase().equals('closed won'))&&((opp.Type.toLowerCase().equals('additional sales'))||(opp.Type.toLowerCase().equals('adjustment'))) && opp.Integration_Product_Attached__c == True))
{
list<Account> acc = [select id, Closed__c from Account where ID=:opp.AccountId];
if (acc[0].Closed__c == TRUE)
{
system.debug('----------opp.AccountId---->'+opp.AccountId);
newcase.AccountId=opp.AccountId;
newcase.Opportunity__c=opp.Id;
newcase.Subject='New Implementation case for '+opp.Account_Name__c;
newcase.Status='New';
newcase.Origin='Sign Up Form';
newcase.Priority='Medium';
newcase.RecordTypeId=recordtype;
newcase.Billing_Email__c = opp.Billing_Email__c;
cases.add(newcase);
}

}
else
{
}
}

if(cases.size()!=0 && cases.size()!=null)
{
system.debug('----------cases.size()---->'+cases.size());
insert cases;
}

 

Thanks in advance!

Hello,

 

I am trying to write a trigger that will create a specific case type when an opportunity meets the following criteria:

 

The opportunity field type = adjustment or initial sale

The opportunity stage = pending setup or closed won

One of the following products is on the opportunity:

  • Product A
  • Product B
  • Product C

I currently have another trigger that is creating a case based off of opportunity fields but am not sure how to associate opportunity products to create this new trigger.  See Below:

 

trigger ImplementationBillingCaseCreation on Opportunity (after insert,after update) {
    string recordtype = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Implementation new').getRecordTypeId();
    List<Case> cases = new List<Case>();
    for (Opportunity opp: Trigger.New)
    { case newcase= new case();
         if((trigger.isInsert && (opp.StageName.toLowerCase().equals('pending setup'))&&(opp.Type.toLowerCase().equals('initial sales')))||(trigger.isInsert && (opp.StageName.toLowerCase().equals('closed won'))&&(opp.Type.toLowerCase().equals('billing sales')))||(trigger.isUpdate &&(opp.StageName !=  Trigger.oldMap.get(opp.Id).StageName && opp.StageName.toLowerCase().equals('pending setup'))&&((opp.Type.toLowerCase().equals('initial sales'))) && !opp.On_Boarding_Case_Created__c)||(trigger.isUpdate &&(opp.StageName !=  Trigger.oldMap.get(opp.Id).StageName && opp.StageName.toLowerCase().equals('closed won'))&&((opp.Type.toLowerCase().equals('billing sales')))))
         {
            system.debug('----------opp.AccountId---->'+opp.AccountId);
            newcase.AccountId=opp.AccountId;
            newcase.Opportunity__c=opp.Id;
            newcase.Subject='New Implementation case for '+opp.Account_Name__c;
            newcase.Status='New';
            newcase.Origin='Sign Up Form';
            newcase.Priority='Medium';
            newcase.RecordTypeId=recordtype;
            cases.add(newcase);
         }
         
    }
    if(cases.size()!=0 && cases.size()!=null)
    {
        system.debug('----------cases.size()---->'+cases.size());
        insert cases;
    }

 

Thank you in advance!

Hello,

 

I am new to Apex triggers and need help on creating one.  My organization has a custom object called product subscriptions.  I would like to run a trigger to checks if a field called quantity on my custom object is equal to 0.  If the quantity is equal to 0 I would like the trigger to delete that record.  Below is the trigger I have started(it may be completely wrong):

 

trigger DeleteZeroQtySubscriptions on Product_Subscription__c (after update, after insert) {
//This trigger deletes any product subscription that has a quantity of 0
//Created by Bennett 1082013

Product_Subscription__c[] toBeDeleted = new list<Product_Subscriptions__c>();

for (Product_Subscription__c sub : Trigger.Old)
{
if (sub.Quantity__c == '0')
{
toBeDeleted.add(sub);
}
}
delete toBeDeleted;
}

 

Also, how can I test this trigger?

 

Thanks,

Hello,

 

I would like to pull an email address from a specfic contact on an account to a custom account field.  I think this can be accomplished by flagging a field on the contact and using that to pull the email address.  I am just not sure where to start.  Should this be a trigger or can this be done in a workflow?

 

Please let me know if you have a solution.

 

Thanks,

Hi All,

 

I have created buttons on a case record type to create child cases when pressed with an app called object converter.  I am looking for  way to show that the button has been pressed and only allow each button to be pressed once.  Please let me know if you have a solution for this issue.

 

Thanks,

Hello,

 

I am looking for a solution to show all contacts in child accounts to the associated parent account.  I was thinking of having a related to list or something similar to show the relationship.  Please let me know if you could help me out or need more clarification.

 

Thanks,

We would like to use public calendars to set up time for the customer to train with our trainers.  I would like it so that a rep that talks to the customer finds out when the customer wants to train can put that event in the "training" public folder and then our trainers can view it.  The problem is that we only have one account for our trainers, so is there a way to show which events is for which trainers?

Hello,

I am new to APEX and was hoping someone could help me.  I am looking to create a class for a button on the case object.  I would like the button to be placed on child cases and retrieve data from certain fields from the parent case.  

I recently created a class for a button on the parent case that will create new child cases and pre-populate certain fields but am not sure how to reverse-engineer my solution for the use case described above.

Can someone please help me write this class or help me write the foundation?

Thanks in advanced.

Hello,

 

I am trying to write a trigger that will create a specific case type when an opportunity meets the following criteria:

 

The opportunity field type = adjustment or initial sale

The opportunity stage = pending setup or closed won

One of the following products is on the opportunity:

  • Product A
  • Product B
  • Product C

I currently have another trigger that is creating a case based off of opportunity fields but am not sure how to associate opportunity products to create this new trigger.  See Below:

 

trigger ImplementationBillingCaseCreation on Opportunity (after insert,after update) {
    string recordtype = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Implementation new').getRecordTypeId();
    List<Case> cases = new List<Case>();
    for (Opportunity opp: Trigger.New)
    { case newcase= new case();
         if((trigger.isInsert && (opp.StageName.toLowerCase().equals('pending setup'))&&(opp.Type.toLowerCase().equals('initial sales')))||(trigger.isInsert && (opp.StageName.toLowerCase().equals('closed won'))&&(opp.Type.toLowerCase().equals('billing sales')))||(trigger.isUpdate &&(opp.StageName !=  Trigger.oldMap.get(opp.Id).StageName && opp.StageName.toLowerCase().equals('pending setup'))&&((opp.Type.toLowerCase().equals('initial sales'))) && !opp.On_Boarding_Case_Created__c)||(trigger.isUpdate &&(opp.StageName !=  Trigger.oldMap.get(opp.Id).StageName && opp.StageName.toLowerCase().equals('closed won'))&&((opp.Type.toLowerCase().equals('billing sales')))))
         {
            system.debug('----------opp.AccountId---->'+opp.AccountId);
            newcase.AccountId=opp.AccountId;
            newcase.Opportunity__c=opp.Id;
            newcase.Subject='New Implementation case for '+opp.Account_Name__c;
            newcase.Status='New';
            newcase.Origin='Sign Up Form';
            newcase.Priority='Medium';
            newcase.RecordTypeId=recordtype;
            cases.add(newcase);
         }
         
    }
    if(cases.size()!=0 && cases.size()!=null)
    {
        system.debug('----------cases.size()---->'+cases.size());
        insert cases;
    }

 

Thank you in advance!

Hello,

 

I am new to Apex triggers and need help on creating one.  My organization has a custom object called product subscriptions.  I would like to run a trigger to checks if a field called quantity on my custom object is equal to 0.  If the quantity is equal to 0 I would like the trigger to delete that record.  Below is the trigger I have started(it may be completely wrong):

 

trigger DeleteZeroQtySubscriptions on Product_Subscription__c (after update, after insert) {
//This trigger deletes any product subscription that has a quantity of 0
//Created by Bennett 1082013

Product_Subscription__c[] toBeDeleted = new list<Product_Subscriptions__c>();

for (Product_Subscription__c sub : Trigger.Old)
{
if (sub.Quantity__c == '0')
{
toBeDeleted.add(sub);
}
}
delete toBeDeleted;
}

 

Also, how can I test this trigger?

 

Thanks,

Hi All,

 

I have created buttons on a case record type to create child cases when pressed with an app called object converter.  I am looking for  way to show that the button has been pressed and only allow each button to be pressed once.  Please let me know if you have a solution for this issue.

 

Thanks,