-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
13Questions
-
18Replies
I could use a little help with a test class for a trigger.
My trigger works and my Test Class have 85% coverage but I would like to know how to get a littl emore coverage.
Not so much for the coverage itself but for the knowlege of how to do this in the future.
My trigger runs for inserts and updates.
My test class covers the insert but not the update and i am not at all; sure how to do both.
Here is the trigger:
This is the main bit that is not covered:
(the "OR" parts).
Any tips on how to cover the update as well as the insert?
Thanks much,
Steve
Not so much for the coverage itself but for the knowlege of how to do this in the future.
My trigger runs for inserts and updates.
My test class covers the insert but not the update and i am not at all; sure how to do both.
Here is the trigger:
trigger createOqNew on Opportunity (after insert, after update) //trigger { // try try{ Id recordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('CDARS_ICS_Prospect').getRecordTypeId(); List <Open_Quarter__c> createOpenQuarter = new List <Open_Quarter__c>(); List <Open_Quarter__c> deleteOpenQuarter = new List <Open_Quarter__c>(); Set <Id> processedOpportunities = new Set <Id>(); // for loop 1 for (Opportunity opportunityList : Trigger.new) { // if loop 1 if (opportunityList.RecordTypeId == recordTypeId) { // if loop 2 if (Trigger.isInsert || (Trigger.isUpdate && opportunityList.Estimated_Start_Quarter__c != Trigger.oldMap.get(opportunityList.Id).Estimated_Start_Quarter__c) || (Trigger.isUpdate && opportunityList.Estimated_Finish_Quarter__c != Trigger.oldMap.get(opportunityList.Id).Estimated_Finish_Quarter__c)){ Decimal year = opportunityList.Start_Year__c; Decimal quarter = opportunityList.Start_Quarter__c; Decimal span = opportunityList.Quarters_Spanned_op__c; processedOpportunities.add(OpportunityList.Id); //for loop 2 for (Integer counter = 0; counter < span; counter++) { Open_Quarter__c oq = new Open_Quarter__C(); oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; oq.Estimated_Finish_Quarter_OQ__c = opportunityList.Estimated_Finish_Quarter__c; oq.Estimated_Start_Quarter_OQ__c = opportunityList.Estimated_Start_Quarter__c; oq.Name = year+'-'+'Q'+quarter; oq.Opportunity_Name_oq__c = opportunityList.Id; createOpenQuarter.add(oq); quarter++; // if loop 3 if (quarter > 4) { quarter = 1; year++; } //end if loop 3 } //end for loop 2 } //end if loop 2 } //end if loop 1 } //end for loop 1 deleteOpenQuarter.addAll ([SELECT Id, Name FROM Open_Quarter__c WHERE Opportunity_Name_oq__c IN :processedOpportunities]); // if loop 4 if (deleteOpenQuarter.isEmpty()==false){ Database.delete (deleteOpenQuarter,false); } // end if loop 4 // if loop 5 if(createOpenQuarter.isEmpty()==false){ Database.insert (createOpenQuarter,false); } // end if loop 5 } // end try //catch catch (Exception e){ //e.getMessage() //e.getLineNumber() throw e; } // end catch } // end triggerAnd here is the test class:
@isTest public class TestCreateOqNew { @isTest static void testForCreateOQ() { Account acct = new Account(Name='Steve Test Account', recordTypeId='01241000001I8KBAA0', Service_Membership__c='Non-Member', Type='Bank'); insert acct; Opportunity opp = new Opportunity(name=acct.Name + 'Opportunity', recordTypeId='01241000001USq9AAG', StageName='Prospecting', CloseDate=System.today().addMonths(6), Estimated_Finish_Quarter__c=System.today().addMonths(6), Estimated_Start_Quarter__c=System.today(), AccountId=acct.Id, Objective__c='Onboard - New', Amount=987654321, LeadSource='Webinar', Product_Type__c='CDARS Reciprocal'); Test.startTest(); insert opp; List<Open_Quarter__c> quarters = [SELECT Id, Name, Amount_Per_Quarter_oq__c, Estimated_Finish_Quarter_OQ__c, Estimated_Start_Quarter_OQ__c , Opportunity_Name_oq__c FROM Open_Quarter__c ORDER BY Name]; Test.stopTest(); System.assertEquals(3, quarters.size()); System.assertEquals('2020-Q2', quarters[0].name); } }
This is the main bit that is not covered:
|| (Trigger.isUpdate && opportunityList.Estimated_Start_Quarter__c != Trigger.oldMap.get(opportunityList.Id).Estimated_Start_Quarter__c) || (Trigger.isUpdate && opportunityList.Estimated_Finish_Quarter__c != Trigger.oldMap.get(opportunityList.Id).Estimated_Finish_Quarter__c)){
(the "OR" parts).
Any tips on how to cover the update as well as the insert?
Thanks much,
Steve
-
- Steve Connelly 5
- April 20, 2020
- Like
- 0
- Continue reading or reply
I need a little help with a trigger please
I have built a trigger that should fire when an Opportunity is created or updated in a particular way.
I was so focused on the update part that I never tested the on insert part until today.
Everything else in trigger works but I can't figure out why it does not execute when the Opp is first created.
Here is the complete trigger:
Any suggestions?
Steve
I was so focused on the update part that I never tested the on insert part until today.
Everything else in trigger works but I can't figure out why it does not execute when the Opp is first created.
Here is the complete trigger:
trigger createOqNew on Opportunity (after insert, after update) //trigger { // try try{ Id recordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('CDARS_ICS_Prospect').getRecordTypeId(); List <Open_Quarter__c> createOpenQuarter = new List <Open_Quarter__c>(); List <Open_Quarter__c> deleteOpenQuarter = new List <Open_Quarter__c>(); // for loop 1 for (Opportunity opportunityList : Trigger.new) { // if loop 1 if (opportunityList.RecordTypeId == recordTypeId) { // if loop 2 if (Trigger.isInsert || (Trigger.isUpdate && opportunityList.Estimated_Start_Quarter__c != Trigger.oldMap.get(opportunityList.Id).Estimated_Start_Quarter__c) || (Trigger.isUpdate && opportunityList.Estimated_Finish_Quarter__c != Trigger.oldMap.get(opportunityList.Id).Estimated_Finish_Quarter__c)){ Decimal year = opportunityList.Start_Year__c; Decimal quarter = opportunityList.Start_Quarter__c; Decimal span = opportunityList.Quarters_Spanned_op__c; //for loop 2 for (Integer counter = 0; counter < span; counter++) { Open_Quarter__c oq = new Open_Quarter__C(); oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; oq.Close_Date_oq__c = opportunityList.CloseDate; oq.Name = year+'-'+'Q'+quarter; oq.Opportunity_Name_oq__c = opportunityList.Id; createOpenQuarter.add(oq); quarter++; // if loop 3 if (quarter > 4) { quarter = 1; year++; } //end if loop 3 } //end for loop 2 } //end if loop 2 } //end if loop 1 } //end for loop 1 deleteOpenQuarter.addAll ([SELECT Id, Name FROM Open_Quarter__c WHERE Opportunity_Name_oq__c IN :trigger.newMap.keySet()]); // if loop 4 if (deleteOpenQuarter.isEmpty()==false){ Database.delete (deleteOpenQuarter,false); } // end if loop 4 // if loop 5 if(createOpenQuarter.isEmpty()==false){ Database.insert (createOpenQuarter,false); } // end if loop 5 } // end try //catch catch (Exception e){ //e.getMessage() //e.getLineNumber() throw e; } // end catch } // end triggerIt seems like it should work on insert but it does not. It only works on update.
Any suggestions?
Steve
-
- Steve Connelly 5
- April 17, 2020
- Like
- 0
- Continue reading or reply
How do i code this?
Stuch on how to code this:
Starting with this…
string created = opportunityList.Quarter_Created_op__c;
decimal year = opportunityList.Start_Year__c;
decimal quarter = opportunityList.Start_Quarter__c;
decimal span = opportunityList.Quarters_Spanned_op__c;
decimal counter1 = 0;
while (counter1 < span )
{
......................................................................
How do I code this?
If quarter is =< 4
Output = year + quarter (for use in next step) should look something like this (2019-Q1 or 2019-Q2 or 2019-Q3 or 2019-Q4)
If quarter is >4 reset quarter to 1
Increment year +1
Output = year + quarter (for use in next step) should look something like this (2020-Q1)
Each time this completes, increment quarter++ until (counter > span)
I will use the output from the above loop in creating a new record.
Any help out there for a newbiw coder?
Thanks much,
Sc
Starting with this…
string created = opportunityList.Quarter_Created_op__c;
decimal year = opportunityList.Start_Year__c;
decimal quarter = opportunityList.Start_Quarter__c;
decimal span = opportunityList.Quarters_Spanned_op__c;
decimal counter1 = 0;
while (counter1 < span )
{
......................................................................
How do I code this?
If quarter is =< 4
Output = year + quarter (for use in next step) should look something like this (2019-Q1 or 2019-Q2 or 2019-Q3 or 2019-Q4)
If quarter is >4 reset quarter to 1
Increment year +1
Output = year + quarter (for use in next step) should look something like this (2020-Q1)
Each time this completes, increment quarter++ until (counter > span)
I will use the output from the above loop in creating a new record.
Any help out there for a newbiw coder?
Thanks much,
Sc
-
- Steve Connelly 5
- April 03, 2020
- Like
- 0
- Continue reading or reply
how do i get a while loop to repeatedly cycle for four digits (1-4)?
If the counter starts at 3 I want it to increment to 4 and then start back at 1, Plus I want it to increment the outer loop by 1.
Then proceed to loop incrementing as needed until the counter is satisfied.
Any thoughts?
Thanks much,
Steve
Then proceed to loop incrementing as needed until the counter is satisfied.
Any thoughts?
Thanks much,
Steve
-
- Steve Connelly 5
- April 03, 2020
- Like
- 0
- Continue reading or reply
Using nested loops to populate field on new record
How do I increnet loops through quarter and year and generate output for field?
Fields in Opp provide year and quarter. opp was created and number of quarters the opp spans
I need loops that will start with the year (ex 2019) and quarter (ex 2) that the opp was created.
Outer loop starts with the year, 2019.
Inner loop starts with the quarter, say 3.
The opp spans 5 quarters so i nee dthis to iterate 5 times.
The output for the first iteration should be 2019-Q3 so i can input that value into the first new record.
The next run increments up the quarter from 3 to four and it creates the next record with 2019-Q4.
The next run needs to do two things...Restart the quarter count back to 1 and increment the year up to 2020 for a result of 2020-Q1
And so forth until we have looped the number of times indicated by the span number.
NOTE I alreadt have the basic loop that creates new records for the correct number of times, I just don't know how to do all this incrementing and creating the incementing output.
Any help out there for a new coder please?
following is the part I am working with
Thans much,
Steve
Fields in Opp provide year and quarter. opp was created and number of quarters the opp spans
I need loops that will start with the year (ex 2019) and quarter (ex 2) that the opp was created.
Outer loop starts with the year, 2019.
Inner loop starts with the quarter, say 3.
The opp spans 5 quarters so i nee dthis to iterate 5 times.
The output for the first iteration should be 2019-Q3 so i can input that value into the first new record.
The next run increments up the quarter from 3 to four and it creates the next record with 2019-Q4.
The next run needs to do two things...Restart the quarter count back to 1 and increment the year up to 2020 for a result of 2020-Q1
And so forth until we have looped the number of times indicated by the span number.
NOTE I alreadt have the basic loop that creates new records for the correct number of times, I just don't know how to do all this incrementing and creating the incementing output.
Any help out there for a new coder please?
following is the part I am working with
string created = opportunityList.Quarter_Created_op__c; decimal year = opportunityList.Start_Year__c; decimal quarter = opportunityList.Start_Quarter__c; decimal span = opportunityList.Quarters_Spanned_op__c; //while loop1 increment quarter decimal counter1 = year; while (counter1 < Year + 1) { //while loop2 increment year decimal counter2 = quarter; while (counter2 < quarter + 1) { counter2++; }//end while loop2 counter1++; }//end while loop1 //while loop3 create record process decimal counter3 = span; while (counter3 < span) { Open_Quarter__c oq = new Open_Quarter__C(); Quarter_Number__c qn = new Quarter_Number__c(); oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; oq.Close_Date_oq__c = opportunityList.CloseDate; oq.Name = opportunityList.Quarter_Created_op__c; oq.Opportunity_Name_oq__c = opportunityList.Id; oq.Quarters_Spanned_oq__c = opportunityList.Quarters_Spanned_op__c; createOpenQuarter.add(oq); counter3++; }//end while loop3
Thans much,
Steve
-
- Steve Connelly 5
- April 03, 2020
- Like
- 0
- Continue reading or reply
how do i create a loop in a trigger that increment quarters and years
I have the starting quarter for an opp. and the number or quarters the opp spans.
I have a trigger that creates new related records for the Opp. Using the above information, how do i loop the trigger to name these new related records with subsequest quarter names?
Thank smuch,
Steve
I have a trigger that creates new related records for the Opp. Using the above information, how do i loop the trigger to name these new related records with subsequest quarter names?
Thank smuch,
Steve
-
- Steve Connelly 5
- April 03, 2020
- Like
- 0
- Continue reading or reply
I could use a little help with nested "while" loops in a trigger.
Good morning all. I have a trigger that creates new records related to opportunities.
I have everything working but my loop and i am stuck. I am very new to coding and would really appreciate some assistance.
This iwhat I have so far and everything works...except....
Now I have four custom formula fields in the opp that I can use.
But the rest is all very new to me. How do I build these nested loops with an output for each iteration that looks like this "2019-Q1" that I can use in creating my new records.
I am really stuck here so any help at all will be greatly appreciated.
Best regards,
Steve
I have everything working but my loop and i am stuck. I am very new to coding and would really appreciate some assistance.
This iwhat I have so far and everything works...except....
//while loop create record process decimal counter = 0; while (counter < opportunityList.Quarters_Spanned_op__c) { Open_Quarter__c oq = new Open_Quarter__C(); Quarter_Number__c qn = new Quarter_Number__c(); oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; oq.Close_Date_oq__c = opportunityList.CloseDate; oq.Name = opportunityList.Quarter_Created_op__c; oq.Opportunity_Name_oq__c = opportunityList.Id; oq.Quarters_Spanned_oq__c = opportunityList.Quarters_Spanned_op__c; createOpenQuarter.add(oq); counter++; }//end while loopWhen I create each new record I need it to populate a field in that record with escalating quarter names. Right now it creates the right nimber of records but they all have the same quarter name in them which the starting quarter of the opp.
Now I have four custom formula fields in the opp that I can use.
- One with the name for the quarter when the opp was created in this format: 2019-Q1 etc
- One with the year the opp was started as a number "2019"
- One with the starting quarter as a number (1-4)
- One with the number of quarters the opp spanse based upon the created and close dates also expressed as a number.
But the rest is all very new to me. How do I build these nested loops with an output for each iteration that looks like this "2019-Q1" that I can use in creating my new records.
I am really stuck here so any help at all will be greatly appreciated.
Best regards,
Steve
-
- Steve Connelly 5
- April 03, 2020
- Like
- 0
- Continue reading or reply
How do i identify and delete records related to an opportunity using trigger?
I have a trigger that creates records related the opportunity that fires the trigger.
I need to add a step that will delete any of these existing records if the close date is updated.
Each opp will have one or more of these related records.
How do i identify / list these records and delete them?
I think I have my conditionals all set up the way I need them. i just need to identify them and delete them.
Any suggestions out there?
Steve
I need to add a step that will delete any of these existing records if the close date is updated.
Each opp will have one or more of these related records.
How do i identify / list these records and delete them?
I think I have my conditionals all set up the way I need them. i just need to identify them and delete them.
Any suggestions out there?
Steve
-
- Steve Connelly 5
- April 02, 2020
- Like
- 0
- Continue reading or reply
How do I limit my trigger to specific record types and field values?
I have a new trigger that creates a custom object record when an opportunity is created or updated.
Everything works but I need help with one thing. I only want it to run when a specific opportunity type is created or when that type has its "cloe date" field updated.
Here is my code:
How do I limit this so it only runs when a "Sales" opp is created or when an existing Sales Opp has the "Close Date" field updated?
New to coding and apex so any help is greatly appreciated.
Best regards,
Steve
Everything works but I need help with one thing. I only want it to run when a specific opportunity type is created or when that type has its "cloe date" field updated.
Here is my code:
trigger createOq on Opportunity (after insert, after update) { List <Open_Quarter__c> createOpenQuarter = new List <Open_Quarter__c> (); for(Opportunity opportunityList : trigger.New){ Open_Quarter__c oq = new Open_Quarter__C(); oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; oq.Close_Date_oq__c = opportunityList.CloseDate; oq.Name = opportunityList.Quarter_Created_op__c; oq.Opportunity_Name_oq__c = opportunityList.Id; oq.Quarters_Spanned_oq__c = opportunityList.Quarters_Spanned_op__c; createOpenQuarter.add(oq); } try { insert createOpenQuarter; } catch (system.Dmlexception e) { system.debug (e); } }
How do I limit this so it only runs when a "Sales" opp is created or when an existing Sales Opp has the "Close Date" field updated?
New to coding and apex so any help is greatly appreciated.
Best regards,
Steve
-
- Steve Connelly 5
- March 27, 2020
- Like
- 0
- Continue reading or reply
Could use some basic coding help
Good morning all,
I am trying to build a trigger that will create a related custom object record when an Opportyunity is created or updated.
This is my code so far:
I am trying to get this a step at a time. So I just want the first step to work.
The trigger is active in my sandbox so i was hoping that when I created a new Opp or updated an existing one that the trigger would create the custom record but nothing happens.
Can you let me know what I am missing or have done wrong? Once this part works i will work on the next step. Just trying to learn as i go.
I am brand new to coding so i appreciate your patience and any help i can get. I do not get any errors with the obove code, but nothing happens either.
Best regards,
Steve
I am trying to build a trigger that will create a related custom object record when an Opportyunity is created or updated.
This is my code so far:
trigger createOpenQuarter on Opportunity (after insert,after update) { List <Open_Quarter__c> createOpenQuarter = new List <Open_Quarter__c> (); Open_Quarter__c oq = new Open_Quarter__c (); Quarter_Number__c qn = new Quarter_Number__c (); Opportunity o = new Opportunity (); oq.Amount_Per_Quarter__c = o.Amount_per_Quarter__c; oq.Close_Date__c = o.CloseDate; oq.Name = o.Quarter_Created__c; oq.Opportunity_Name__c = o.Name; oq.Quarters_Spanned__c = o.Quarters_Spanned__c; createOpenQuarter.add(oq); try { insert createOpenQuarter; } catch (system.Dmlexception e) { system.debug (e); } }
I am trying to get this a step at a time. So I just want the first step to work.
The trigger is active in my sandbox so i was hoping that when I created a new Opp or updated an existing one that the trigger would create the custom record but nothing happens.
Can you let me know what I am missing or have done wrong? Once this part works i will work on the next step. Just trying to learn as i go.
I am brand new to coding so i appreciate your patience and any help i can get. I do not get any errors with the obove code, but nothing happens either.
Best regards,
Steve
-
- Steve Connelly 5
- March 27, 2020
- Like
- 0
- Continue reading or reply
Creating a self service deduping tool with Flow and Invokable Method - Stuck on the code
I am so close on this one I think. I have built an invocable method to pass two contacts from a flow into Apex to merge the contacts but I am stuck in the part of the code to pass the IDs into the merge command.
Here is the code:

The code indicates that there the survivorCont and mergeCont variables do not exist.
I feel like I am very close on this one but could ureally use some help taking this accross the finish line.
Any thought sout there on this one?
Thanks much
Steve
Here is the code:
The code indicates that there the survivorCont and mergeCont variables do not exist.
I feel like I am very close on this one but could ureally use some help taking this accross the finish line.
Any thought sout there on this one?
Thanks much
Steve
-
- Steve Connelly 5
- October 31, 2019
- Like
- 0
- Continue reading or reply
How to user merge call with an invocable method to merge contact records.
Good afternoon all, I am working in Lightning.
I have a flow that i will be using for a self service deduping tool. I find that I need to pass data out of the flow and into Apex using an invocable method and i am not sure how to do that. i have very limited coding skills and could use some pointers.
I have looked up how to build an invocable method and how to use the merge call and tried to piece something togethe rthat will work but there are a few things I really need help with.
For example, the code I have has places for the contact IDs but I am unsure how these are passed into the code from the flow. Do I enter the variable the IDs are stored in from the flow?
Following is what I have so far so maybe you can point me in the right direction. As I mentioned, i am very new to coding so please forgive me for any glaring mistakes.
It is fine if you can just point me in the direction of some example sthat might help too.
All I need to do is pass two contact IDs through an ivocable method from a flow and have the method merge the two and delete the duplicate once merged.
Any help at all will be greatly appreciated.
Best regards,
Steve
I have a flow that i will be using for a self service deduping tool. I find that I need to pass data out of the flow and into Apex using an invocable method and i am not sure how to do that. i have very limited coding skills and could use some pointers.
I have looked up how to build an invocable method and how to use the merge call and tried to piece something togethe rthat will work but there are a few things I really need help with.
For example, the code I have has places for the contact IDs but I am unsure how these are passed into the code from the flow. Do I enter the variable the IDs are stored in from the flow?
Following is what I have so far so maybe you can point me in the right direction. As I mentioned, i am very new to coding so please forgive me for any glaring mistakes.
It is fine if you can just point me in the direction of some example sthat might help too.
All I need to do is pass two contact IDs through an ivocable method from a flow and have the method merge the two and delete the duplicate once merged.
Any help at all will be greatly appreciated.
Best regards,
Steve
-
- Steve Connelly 5
- October 28, 2019
- Like
- 0
- Continue reading or reply
How do I pull a case ID into a flow?
I am working in Lightning.
I have created a lightning component to launch a flow from a case. How do I pull the case ID into the flow? Once I get the case that the flow was launched from, i can get everything else I need through the flow.
I am new to all this so basic steps if possible.
My lightning component is writtem in HTML and CSS.
Any help will be greatly appreciated.
Best regards,
Steve
I have created a lightning component to launch a flow from a case. How do I pull the case ID into the flow? Once I get the case that the flow was launched from, i can get everything else I need through the flow.
I am new to all this so basic steps if possible.
My lightning component is writtem in HTML and CSS.
Any help will be greatly appreciated.
Best regards,
Steve
-
- Steve Connelly 5
- August 22, 2019
- Like
- 0
- Continue reading or reply
I need a little help with a trigger please
I have built a trigger that should fire when an Opportunity is created or updated in a particular way.
I was so focused on the update part that I never tested the on insert part until today.
Everything else in trigger works but I can't figure out why it does not execute when the Opp is first created.
Here is the complete trigger:
Any suggestions?
Steve
I was so focused on the update part that I never tested the on insert part until today.
Everything else in trigger works but I can't figure out why it does not execute when the Opp is first created.
Here is the complete trigger:
trigger createOqNew on Opportunity (after insert, after update) //trigger { // try try{ Id recordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('CDARS_ICS_Prospect').getRecordTypeId(); List <Open_Quarter__c> createOpenQuarter = new List <Open_Quarter__c>(); List <Open_Quarter__c> deleteOpenQuarter = new List <Open_Quarter__c>(); // for loop 1 for (Opportunity opportunityList : Trigger.new) { // if loop 1 if (opportunityList.RecordTypeId == recordTypeId) { // if loop 2 if (Trigger.isInsert || (Trigger.isUpdate && opportunityList.Estimated_Start_Quarter__c != Trigger.oldMap.get(opportunityList.Id).Estimated_Start_Quarter__c) || (Trigger.isUpdate && opportunityList.Estimated_Finish_Quarter__c != Trigger.oldMap.get(opportunityList.Id).Estimated_Finish_Quarter__c)){ Decimal year = opportunityList.Start_Year__c; Decimal quarter = opportunityList.Start_Quarter__c; Decimal span = opportunityList.Quarters_Spanned_op__c; //for loop 2 for (Integer counter = 0; counter < span; counter++) { Open_Quarter__c oq = new Open_Quarter__C(); oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; oq.Close_Date_oq__c = opportunityList.CloseDate; oq.Name = year+'-'+'Q'+quarter; oq.Opportunity_Name_oq__c = opportunityList.Id; createOpenQuarter.add(oq); quarter++; // if loop 3 if (quarter > 4) { quarter = 1; year++; } //end if loop 3 } //end for loop 2 } //end if loop 2 } //end if loop 1 } //end for loop 1 deleteOpenQuarter.addAll ([SELECT Id, Name FROM Open_Quarter__c WHERE Opportunity_Name_oq__c IN :trigger.newMap.keySet()]); // if loop 4 if (deleteOpenQuarter.isEmpty()==false){ Database.delete (deleteOpenQuarter,false); } // end if loop 4 // if loop 5 if(createOpenQuarter.isEmpty()==false){ Database.insert (createOpenQuarter,false); } // end if loop 5 } // end try //catch catch (Exception e){ //e.getMessage() //e.getLineNumber() throw e; } // end catch } // end triggerIt seems like it should work on insert but it does not. It only works on update.
Any suggestions?
Steve
- Steve Connelly 5
- April 17, 2020
- Like
- 0
- Continue reading or reply
how do i get a while loop to repeatedly cycle for four digits (1-4)?
If the counter starts at 3 I want it to increment to 4 and then start back at 1, Plus I want it to increment the outer loop by 1.
Then proceed to loop incrementing as needed until the counter is satisfied.
Any thoughts?
Thanks much,
Steve
Then proceed to loop incrementing as needed until the counter is satisfied.
Any thoughts?
Thanks much,
Steve
- Steve Connelly 5
- April 03, 2020
- Like
- 0
- Continue reading or reply
Using nested loops to populate field on new record
How do I increnet loops through quarter and year and generate output for field?
Fields in Opp provide year and quarter. opp was created and number of quarters the opp spans
I need loops that will start with the year (ex 2019) and quarter (ex 2) that the opp was created.
Outer loop starts with the year, 2019.
Inner loop starts with the quarter, say 3.
The opp spans 5 quarters so i nee dthis to iterate 5 times.
The output for the first iteration should be 2019-Q3 so i can input that value into the first new record.
The next run increments up the quarter from 3 to four and it creates the next record with 2019-Q4.
The next run needs to do two things...Restart the quarter count back to 1 and increment the year up to 2020 for a result of 2020-Q1
And so forth until we have looped the number of times indicated by the span number.
NOTE I alreadt have the basic loop that creates new records for the correct number of times, I just don't know how to do all this incrementing and creating the incementing output.
Any help out there for a new coder please?
following is the part I am working with
Thans much,
Steve
Fields in Opp provide year and quarter. opp was created and number of quarters the opp spans
I need loops that will start with the year (ex 2019) and quarter (ex 2) that the opp was created.
Outer loop starts with the year, 2019.
Inner loop starts with the quarter, say 3.
The opp spans 5 quarters so i nee dthis to iterate 5 times.
The output for the first iteration should be 2019-Q3 so i can input that value into the first new record.
The next run increments up the quarter from 3 to four and it creates the next record with 2019-Q4.
The next run needs to do two things...Restart the quarter count back to 1 and increment the year up to 2020 for a result of 2020-Q1
And so forth until we have looped the number of times indicated by the span number.
NOTE I alreadt have the basic loop that creates new records for the correct number of times, I just don't know how to do all this incrementing and creating the incementing output.
Any help out there for a new coder please?
following is the part I am working with
string created = opportunityList.Quarter_Created_op__c; decimal year = opportunityList.Start_Year__c; decimal quarter = opportunityList.Start_Quarter__c; decimal span = opportunityList.Quarters_Spanned_op__c; //while loop1 increment quarter decimal counter1 = year; while (counter1 < Year + 1) { //while loop2 increment year decimal counter2 = quarter; while (counter2 < quarter + 1) { counter2++; }//end while loop2 counter1++; }//end while loop1 //while loop3 create record process decimal counter3 = span; while (counter3 < span) { Open_Quarter__c oq = new Open_Quarter__C(); Quarter_Number__c qn = new Quarter_Number__c(); oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; oq.Close_Date_oq__c = opportunityList.CloseDate; oq.Name = opportunityList.Quarter_Created_op__c; oq.Opportunity_Name_oq__c = opportunityList.Id; oq.Quarters_Spanned_oq__c = opportunityList.Quarters_Spanned_op__c; createOpenQuarter.add(oq); counter3++; }//end while loop3
Thans much,
Steve
- Steve Connelly 5
- April 03, 2020
- Like
- 0
- Continue reading or reply
I could use a little help with nested "while" loops in a trigger.
Good morning all. I have a trigger that creates new records related to opportunities.
I have everything working but my loop and i am stuck. I am very new to coding and would really appreciate some assistance.
This iwhat I have so far and everything works...except....
Now I have four custom formula fields in the opp that I can use.
But the rest is all very new to me. How do I build these nested loops with an output for each iteration that looks like this "2019-Q1" that I can use in creating my new records.
I am really stuck here so any help at all will be greatly appreciated.
Best regards,
Steve
I have everything working but my loop and i am stuck. I am very new to coding and would really appreciate some assistance.
This iwhat I have so far and everything works...except....
//while loop create record process decimal counter = 0; while (counter < opportunityList.Quarters_Spanned_op__c) { Open_Quarter__c oq = new Open_Quarter__C(); Quarter_Number__c qn = new Quarter_Number__c(); oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; oq.Close_Date_oq__c = opportunityList.CloseDate; oq.Name = opportunityList.Quarter_Created_op__c; oq.Opportunity_Name_oq__c = opportunityList.Id; oq.Quarters_Spanned_oq__c = opportunityList.Quarters_Spanned_op__c; createOpenQuarter.add(oq); counter++; }//end while loopWhen I create each new record I need it to populate a field in that record with escalating quarter names. Right now it creates the right nimber of records but they all have the same quarter name in them which the starting quarter of the opp.
Now I have four custom formula fields in the opp that I can use.
- One with the name for the quarter when the opp was created in this format: 2019-Q1 etc
- One with the year the opp was started as a number "2019"
- One with the starting quarter as a number (1-4)
- One with the number of quarters the opp spanse based upon the created and close dates also expressed as a number.
But the rest is all very new to me. How do I build these nested loops with an output for each iteration that looks like this "2019-Q1" that I can use in creating my new records.
I am really stuck here so any help at all will be greatly appreciated.
Best regards,
Steve
- Steve Connelly 5
- April 03, 2020
- Like
- 0
- Continue reading or reply
How do I limit my trigger to specific record types and field values?
I have a new trigger that creates a custom object record when an opportunity is created or updated.
Everything works but I need help with one thing. I only want it to run when a specific opportunity type is created or when that type has its "cloe date" field updated.
Here is my code:
How do I limit this so it only runs when a "Sales" opp is created or when an existing Sales Opp has the "Close Date" field updated?
New to coding and apex so any help is greatly appreciated.
Best regards,
Steve
Everything works but I need help with one thing. I only want it to run when a specific opportunity type is created or when that type has its "cloe date" field updated.
Here is my code:
trigger createOq on Opportunity (after insert, after update) { List <Open_Quarter__c> createOpenQuarter = new List <Open_Quarter__c> (); for(Opportunity opportunityList : trigger.New){ Open_Quarter__c oq = new Open_Quarter__C(); oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; oq.Close_Date_oq__c = opportunityList.CloseDate; oq.Name = opportunityList.Quarter_Created_op__c; oq.Opportunity_Name_oq__c = opportunityList.Id; oq.Quarters_Spanned_oq__c = opportunityList.Quarters_Spanned_op__c; createOpenQuarter.add(oq); } try { insert createOpenQuarter; } catch (system.Dmlexception e) { system.debug (e); } }
How do I limit this so it only runs when a "Sales" opp is created or when an existing Sales Opp has the "Close Date" field updated?
New to coding and apex so any help is greatly appreciated.
Best regards,
Steve
- Steve Connelly 5
- March 27, 2020
- Like
- 0
- Continue reading or reply
Could use some basic coding help
Good morning all,
I am trying to build a trigger that will create a related custom object record when an Opportyunity is created or updated.
This is my code so far:
I am trying to get this a step at a time. So I just want the first step to work.
The trigger is active in my sandbox so i was hoping that when I created a new Opp or updated an existing one that the trigger would create the custom record but nothing happens.
Can you let me know what I am missing or have done wrong? Once this part works i will work on the next step. Just trying to learn as i go.
I am brand new to coding so i appreciate your patience and any help i can get. I do not get any errors with the obove code, but nothing happens either.
Best regards,
Steve
I am trying to build a trigger that will create a related custom object record when an Opportyunity is created or updated.
This is my code so far:
trigger createOpenQuarter on Opportunity (after insert,after update) { List <Open_Quarter__c> createOpenQuarter = new List <Open_Quarter__c> (); Open_Quarter__c oq = new Open_Quarter__c (); Quarter_Number__c qn = new Quarter_Number__c (); Opportunity o = new Opportunity (); oq.Amount_Per_Quarter__c = o.Amount_per_Quarter__c; oq.Close_Date__c = o.CloseDate; oq.Name = o.Quarter_Created__c; oq.Opportunity_Name__c = o.Name; oq.Quarters_Spanned__c = o.Quarters_Spanned__c; createOpenQuarter.add(oq); try { insert createOpenQuarter; } catch (system.Dmlexception e) { system.debug (e); } }
I am trying to get this a step at a time. So I just want the first step to work.
The trigger is active in my sandbox so i was hoping that when I created a new Opp or updated an existing one that the trigger would create the custom record but nothing happens.
Can you let me know what I am missing or have done wrong? Once this part works i will work on the next step. Just trying to learn as i go.
I am brand new to coding so i appreciate your patience and any help i can get. I do not get any errors with the obove code, but nothing happens either.
Best regards,
Steve
- Steve Connelly 5
- March 27, 2020
- Like
- 0
- Continue reading or reply
How to user merge call with an invocable method to merge contact records.
Good afternoon all, I am working in Lightning.
I have a flow that i will be using for a self service deduping tool. I find that I need to pass data out of the flow and into Apex using an invocable method and i am not sure how to do that. i have very limited coding skills and could use some pointers.
I have looked up how to build an invocable method and how to use the merge call and tried to piece something togethe rthat will work but there are a few things I really need help with.
For example, the code I have has places for the contact IDs but I am unsure how these are passed into the code from the flow. Do I enter the variable the IDs are stored in from the flow?
Following is what I have so far so maybe you can point me in the right direction. As I mentioned, i am very new to coding so please forgive me for any glaring mistakes.
It is fine if you can just point me in the direction of some example sthat might help too.
All I need to do is pass two contact IDs through an ivocable method from a flow and have the method merge the two and delete the duplicate once merged.
Any help at all will be greatly appreciated.
Best regards,
Steve
I have a flow that i will be using for a self service deduping tool. I find that I need to pass data out of the flow and into Apex using an invocable method and i am not sure how to do that. i have very limited coding skills and could use some pointers.
I have looked up how to build an invocable method and how to use the merge call and tried to piece something togethe rthat will work but there are a few things I really need help with.
For example, the code I have has places for the contact IDs but I am unsure how these are passed into the code from the flow. Do I enter the variable the IDs are stored in from the flow?
Following is what I have so far so maybe you can point me in the right direction. As I mentioned, i am very new to coding so please forgive me for any glaring mistakes.
It is fine if you can just point me in the direction of some example sthat might help too.
All I need to do is pass two contact IDs through an ivocable method from a flow and have the method merge the two and delete the duplicate once merged.
Any help at all will be greatly appreciated.
Best regards,
Steve
- Steve Connelly 5
- October 28, 2019
- Like
- 0
- Continue reading or reply
How do I pull a case ID into a flow?
I am working in Lightning.
I have created a lightning component to launch a flow from a case. How do I pull the case ID into the flow? Once I get the case that the flow was launched from, i can get everything else I need through the flow.
I am new to all this so basic steps if possible.
My lightning component is writtem in HTML and CSS.
Any help will be greatly appreciated.
Best regards,
Steve
I have created a lightning component to launch a flow from a case. How do I pull the case ID into the flow? Once I get the case that the flow was launched from, i can get everything else I need through the flow.
I am new to all this so basic steps if possible.
My lightning component is writtem in HTML and CSS.
Any help will be greatly appreciated.
Best regards,
Steve
- Steve Connelly 5
- August 22, 2019
- Like
- 0
- Continue reading or reply