Following from my previous question I'm still trying to link Opportunities and Cotnracts together and report on them.
Firstly, I now have a lookup relationship between Opportunities and Contracts so that my users can now create a contract straight from their opportunities.
I've gone down the road of creating a custom object to serve as a data junction. This object contains the Master-Detail fields Opportunity__c (and Opportunity Name lookup field) and Contract__c (a Contract Number lookup field).
I had the thought of creating some Apex triggers to populate these fields upon creation of an Opportunity and Contract. My first attempt, populating the Opportunity__c field with the Opportunity.Name field is thus:
trigger ApplyOppNameToJunction on Opportunity (before insert) {
Opportunities_and_Contracts__c bb = Opportunity__c;
for (Opportunity aa : trigger.new){
aa.Opportunity.Name = bb.Opportunity__c;
}
}
but this won't save. It tells me
Error: Compile Error: Variable does not exist: Opportunity_c at line 2 column 40
even though that field does exist within the Opportunities_and_Contracts__c object. As this is only stage one and I'm aleady htiting stumbling blocks, can anybody offer any advice?
I do have more queries too:
Once this si sorted, I can set something similar to populate the Contract__c field. My hope is that this would then happen:
User creates Opportunity - Opportunity name automaitcally populated in junction record. User creates Contract from Opportunity - Contract number automatically populated into related junction record.
Can anyone point out if I need anything else to get this to work?