Header Ads Widget

Formula Field Type Conversion || interview stuff


Formula Field Type Conversion

Issue on Formula field type conversion into Text or other field types:

Sales force developers have faced the issue related with Formula field type conversion into other Field Type. Reason behind the issue is there are no configurations available to convert the Formula field type conversion. We can say this is the one the limitation of Salesforce.com and we can not change the type of formulae field.

To avoid the Formula Type conversion:

We can solve the issue like there are 4 to 5 formulae fields are used in page layout which populated the values but earlier requirement was populate the value according to the record created by Partner users. Now the new requirement has changed and these fields populate the value according to the either record created by Standard Users or Partner user.
We could change the formula according to the created by user however there is more than two level hierarchy field. Means we cannot use the field of grandparent standard object fields. For example we need to populate Opportunity’s>Account’s>Contact data. This is not feasible to do populate so we could do this by using of Code.

OLD Formula is Link ID = CreatedBy.Contact.Account.BP_Link_Id__c

Used the following steps to overcome the above issue.

1.            We need to create new text fields name like formulae fields. Like Link_Id__c (Formulae) Link_Ids__c (Text), etc.

2.            Than write the code in to Trigger and initiate the value in to new fields. For this we do SOQL on Opportunity and Oppty Partners to fetched the partner’s name and other values.

3.            Trigger Code:



Map mapOpptyPartner = new Map();

Opportunity opp= new Opportunity();

Map oppMap = new Map([Select Id, Name, OwnerId, Owner.Name from Opportunity WHERE Id in: Trigger. newMap.Id]);

mapOpptyPartner.put(opp.Opportunity__c, opp); //Add Oppty into Map

for(Sale__c saleObj: trigger.new){

if(saleObj.Opportunity_Name__c!=null){

salesObj. field11__c = mapOppPartner.get(salesObj.Opportunity_Name__c).Role__c;

salesObj.field22__c = mapOppPartner.get(salesObj.Opportunity_Name__c). r_name;

salesObj. field33__c = mapOpptyPartner.get(salesObj.Opportunity_Name__c).name;

salesObj. field44__c = mapOppPartner.get(salesObj.Opportunity_Name__c).City;

}}

Description:

Above code fetched all records of the Oppty on Sales record and populated value in these fields.

4.            After instantiate the new Fields value use the these fields into Formula field and populate the current correct value in to the Formula fields. Like

Old formulae field the value Link ID = CreatedBy.Contact.Account.BP_Link_Id__c

New Value on formulae Link ID = Field11__c; etc

Conclusion:

Hence above steps will solve the issue of Formula conversion in to other field type.

Post a Comment

0 Comments