Well, lets pause the coding life for minute and do it using Calculated Fields which used simple UI like business rules.
In Scenario below , i am retrieving the Budget Allocated amount from source campaign on a lead record.
- Create a currency Calculated field on lead record :Give the appropriator name , select data type as Currency or as per your need > Select Field type as Calculated and click on Edit. As soon as you click on edit, system will actually create this field for you.
- After clicking on Edit button , you will be presented with the UI where you have put in your logic:
As a first step i am checking if Budget Allocated field on campaign actually has data.To do this you have select Source campaign in the Entity and the corresponding field.
- Once this condition is set click on the Action :
In the editor start the typing the name of source campaign lookup or you can scroll though all fields/lookups available on the lead entity. Here i have select campaignid
- Once selected the campaignid , enter a dot(.) – post which you will start getting fields from the campaign:
Here i am selecting the budgetcost(Allocated Budget)
- Finally it will look like below :Save and close the editor and also the field property window.
- Put this calculated field on the form and publish customization.
- Open a lead which has campaign associated to it:
It is a very basic example i showed , i tried not to make it complex as it might become very confusing for a beginner. You can do a lot manipulation with the data by using out of the box functions that are available for a calculated field or apply your custom logic.hope this helps!