• Daniel Probert
  • NEWBIE
  • 25 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

Hi,

 

I have a challenge that I can't for the life of me work out how to approach, I have 3 objects that need to be automatically linked, to help explain the Org setup here is a brief.

 

Object 1 = Entitlement__c

 

This has 5 fields in there:

 

Term__c - this is a picklist that has the option Term 1, 2 & 3

Year__c - this is a picklist that has the year 2012-2020

Student__c - this is a lookup to the Contact object

Entitlement_Sheet__c - this is a lookup to a custom object Entitlement_Sheet__c

District_Entitlement_Sheet__c - this is a lookup to a custom object District_Entitlement_Sheet__c

 

Object 2 = District_Entitlement_Sheet__c

 

This has 3 fields in there

 

Term__c - this is a picklist that has the option Term 1, 2 & 3

Year__c - this is a picklist that has the year 2012-2020

District__c - this is a lookup to a custom object District__c

 

Object 3 = Entitlement_Sheet__c

 

This has 3 fields in there

Term__c - this is a picklist that has the option Term 1, 2 & 3

Year__c - this is a picklist that has the year 2012-2020

 School__c - this is a lookup to a custom object School__c

 

My problem is this.

 

I need to create a trigger that when a new Entitlement__c is created it will automatically update the lookup fields Entitlement_Sheet__c & District_Entitlement_Sheet__c.

 

The logic on the connection for mapping Object 1 to 2 is:

 

If the following statement = true then update the Entitlement__c.District_Entitlement_Sheet__c with the ID of the District_Entitlement_Sheet__c.id

 

Entitlement__c.Term__c = District_Entitlement_Sheet__c.Term__c

Entitlement__c.Year__c = District_Entitlement_Sheet__c.Year__c

Entitlement__c.Student__c.District__c.ID = Districit_Entitlement_Sheet__c.District__c.id

 

The logic on the connection for mapping Object 1 to 3 is:

 

Entitlement__c.Term__c = Entitlement_Sheet__c.Term__c

Entitlement__c.Year__c = Entitlement_Sheet__c.Year__c

Entitlement__c.Student__c.School__c.ID = Entitlement_Sheet__c.School__c.id

 

I can't even begin to work out how I would approach this I'm pretty sure it can be done within a single trigger that occurs when a record is inserted but want to be sure.

 

As an FYI the Object 2 & 3 are pre loaded into the system and do contain much more information within them that feeds into formulas within Object 1.

 

Any guidance would be appreciated as I'm clueless on this one :)

 

 

 

 

 

 

 

 

 

Hi Community,

 

I'm new to apex and trigger but have created a simple trigger against a custom object Loan__c that after insert will create the repayment schedule in the custom related object Loan_Repayment__c

 

trigger generateloanrepayments on Loan__c (after insert) {
List <Loan_Repayments__c> prefToInsert = new List <Loan_Repayments__c> ();


for (Loan__c c : Trigger.new) {
Loan_Repayments__c p = new Loan_Repayments__c ();

p.Loan__c = c.Id;
p.Expected_Repayment_Date__c = c.Hidden_First_Payment_Date__c + 30;
p.CurrencyISOCode = c.CurrencyISOCode;

prefToInsert.add(p);

}
try {
insert prefToInsert;
} catch (system.Dmlexception e) {
system.debug (e);
}
}

 

 

This works well however what I now need to do is have this loop and create the entire repayment schedule based on the value that is stored in Loan__c.Number_of_Repayments__c.

 

So when Loan__c.Number_Of_Repayments__c = 5 there are 5 records creates.

 

Hope this makes sense and someone can help me.

 

Cheers

Dan

Hi,

 

I have a challenge that I can't for the life of me work out how to approach, I have 3 objects that need to be automatically linked, to help explain the Org setup here is a brief.

 

Object 1 = Entitlement__c

 

This has 5 fields in there:

 

Term__c - this is a picklist that has the option Term 1, 2 & 3

Year__c - this is a picklist that has the year 2012-2020

Student__c - this is a lookup to the Contact object

Entitlement_Sheet__c - this is a lookup to a custom object Entitlement_Sheet__c

District_Entitlement_Sheet__c - this is a lookup to a custom object District_Entitlement_Sheet__c

 

Object 2 = District_Entitlement_Sheet__c

 

This has 3 fields in there

 

Term__c - this is a picklist that has the option Term 1, 2 & 3

Year__c - this is a picklist that has the year 2012-2020

District__c - this is a lookup to a custom object District__c

 

Object 3 = Entitlement_Sheet__c

 

This has 3 fields in there

Term__c - this is a picklist that has the option Term 1, 2 & 3

Year__c - this is a picklist that has the year 2012-2020

 School__c - this is a lookup to a custom object School__c

 

My problem is this.

 

I need to create a trigger that when a new Entitlement__c is created it will automatically update the lookup fields Entitlement_Sheet__c & District_Entitlement_Sheet__c.

 

The logic on the connection for mapping Object 1 to 2 is:

 

If the following statement = true then update the Entitlement__c.District_Entitlement_Sheet__c with the ID of the District_Entitlement_Sheet__c.id

 

Entitlement__c.Term__c = District_Entitlement_Sheet__c.Term__c

Entitlement__c.Year__c = District_Entitlement_Sheet__c.Year__c

Entitlement__c.Student__c.District__c.ID = Districit_Entitlement_Sheet__c.District__c.id

 

The logic on the connection for mapping Object 1 to 3 is:

 

Entitlement__c.Term__c = Entitlement_Sheet__c.Term__c

Entitlement__c.Year__c = Entitlement_Sheet__c.Year__c

Entitlement__c.Student__c.School__c.ID = Entitlement_Sheet__c.School__c.id

 

I can't even begin to work out how I would approach this I'm pretty sure it can be done within a single trigger that occurs when a record is inserted but want to be sure.

 

As an FYI the Object 2 & 3 are pre loaded into the system and do contain much more information within them that feeds into formulas within Object 1.

 

Any guidance would be appreciated as I'm clueless on this one :)

 

 

 

 

 

 

 

 

 

Hi Community,

 

I'm new to apex and trigger but have created a simple trigger against a custom object Loan__c that after insert will create the repayment schedule in the custom related object Loan_Repayment__c

 

trigger generateloanrepayments on Loan__c (after insert) {
List <Loan_Repayments__c> prefToInsert = new List <Loan_Repayments__c> ();


for (Loan__c c : Trigger.new) {
Loan_Repayments__c p = new Loan_Repayments__c ();

p.Loan__c = c.Id;
p.Expected_Repayment_Date__c = c.Hidden_First_Payment_Date__c + 30;
p.CurrencyISOCode = c.CurrencyISOCode;

prefToInsert.add(p);

}
try {
insert prefToInsert;
} catch (system.Dmlexception e) {
system.debug (e);
}
}

 

 

This works well however what I now need to do is have this loop and create the entire repayment schedule based on the value that is stored in Loan__c.Number_of_Repayments__c.

 

So when Loan__c.Number_Of_Repayments__c = 5 there are 5 records creates.

 

Hope this makes sense and someone can help me.

 

Cheers

Dan