function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cricketlangcricketlang 

Button That Pulls Data From a Related Account

i have a button that will be used to update particular fields on the Account level from many different objects (ie Opportunites and some custom objects we have developed) Due to my lack of a better solution, and knowledge to create a better one, i have thought of doing a simple URL to update this information on a separate object and then have that object save back to the Account fields every time through a trigger. im probably explaining this horribly so let me show you

 

 

/a09/e?id={!Account.Phase_IIIId__c}&00N80000004I201={!Account.State_of_the_Union__c}&00N80000004I206={!Account.Objective__c}&00N80000004I20B={!Account.Critical_Success_Factors__c}&00N80000004I20G={!Account.Customers_Strategy__c}&00N80000004I20L={!Account.Winnable_Position__c}&00N80000004I20Q={!Account.Supporting_Tactics__c}&00N80000004I20V={!Account.Competitors_Strategy__c}

 

so this is a button on the Account level. The user hits the button and is redirected to the second object (phase III) where the default information from the Account fields prepopulate the corresponding fields on the Phase III object. This works just the way we want it to. the user can then change the values and save, on which a trigger updates the account info.

 

NOTE: if anyone has a better solution im open to it. 

 

the issue im facing now is that i have an opportunity, related to an account. i need this button to pull those fields from the account and do the same thing: prepopulate the corresponding fields on the Phase III object so they can modify the values if they want to and save back to the account fields. 

 

As of now i dont know how to do this. i only know how to prepopulate with fields that exist on the object im currently working with, i dont know how to pull fields from a related object (Account)

 

So im either looking for help with getting the fields from the related object, or a better solution. the purpose of this whole thing is so the user can update Account fields from many different objects, but also have the current value of that field as the default value. 

 

Any help is appreciated


 

Best Answer chosen by Admin (Salesforce Developers) 
Ispita_NavatarIspita_Navatar
I need to know few things:-
1. From your code it seems PhaseIII object is related via lookup relationship with the account? Is that so?
2. If answer to 1. is yes then a similar relationship with opportunity will be needed to achieve what you want that is assessing the PhaseIII object
3. Now coming to the other part to access the account information for that you need to the related information onto Opportunity level with the help of "Formula Field".
Say   you have a formula field "XYZ" set to Account.State_of_the_Union__c, repeat for other field
Now for the button code it will somewhat like this:-
/a09/e?id={!Opportunity.Phase_IIIId__c}&00N80000004I201={!Opportunity.XYZ__c}&00N80000004I206
here XYZ stores Account.Stae_of_Union__c at opportunity
The rest also will be replaced accordingly by rspective formula fields at opportunity level:-

={!Account.Objective__c}&00N80000004I20B={!Account.Critical_Success_Factors__c}&00N80000004I20G={!Account.Customers_Strategy__c}&00N80000004I20L={!Account.Winnable_Position__c}&00N80000004I20Q={!Account.Supporting_Tactics__c}&00N80000004I20V={!Account.Competitors_Strategy__c}

Hope this helps.


All Answers

Ispita_NavatarIspita_Navatar
I need to know few things:-
1. From your code it seems PhaseIII object is related via lookup relationship with the account? Is that so?
2. If answer to 1. is yes then a similar relationship with opportunity will be needed to achieve what you want that is assessing the PhaseIII object
3. Now coming to the other part to access the account information for that you need to the related information onto Opportunity level with the help of "Formula Field".
Say   you have a formula field "XYZ" set to Account.State_of_the_Union__c, repeat for other field
Now for the button code it will somewhat like this:-
/a09/e?id={!Opportunity.Phase_IIIId__c}&00N80000004I201={!Opportunity.XYZ__c}&00N80000004I206
here XYZ stores Account.Stae_of_Union__c at opportunity
The rest also will be replaced accordingly by rspective formula fields at opportunity level:-

={!Account.Objective__c}&00N80000004I20B={!Account.Critical_Success_Factors__c}&00N80000004I20G={!Account.Customers_Strategy__c}&00N80000004I20L={!Account.Winnable_Position__c}&00N80000004I20Q={!Account.Supporting_Tactics__c}&00N80000004I20V={!Account.Competitors_Strategy__c}

Hope this helps.


This was selected as the best answer
cricketlangcricketlang

Your answer helps a little bit but im a little confused when it comes to making further relationships (i appologize for this)

 

let me better explain so that you can get a better understanding

 

Phase III right now is a custom object. it is not necessary to be one. all i need to do is be able to update particular account fields from any object where the account is related. on an opportunity, the account is related and therefore should be a way to request those fields being that relationship is establised. 

 

What we would LIKE is simply a pop up window with those fields and thier current values opened in edit mode. the user would then update whats necessary and click save, which will activate a trigger updating account fields.

 

 

From what your instructing, i create formula fields which are just meant to be containers to hold data between objects. Although this works, i dont know if its what we are looking to do. im wondering if visualforce may be a better option? then i can do something like this:

 

 

var result= sforce.connection.retrieve("Competitors_Strategy__c, Critical_Success_Factors__c,Customers_Strategy__c,Objective__c,Winnable_Position__c ,Supporting_Tactics__c,State_of_the_Union__c", "Account", [AccountId], {onSuccess: filldata, onFailure: failure});

 

 

 

cricketlangcricketlang
So i just wanted to follow up and say that the solution provided ended up working better than the idea that we had. we went ahead and just added formula fields that allow the user to only view the data (using like an Account.State_Of_The_Union formula) and then hitting the button which prepopulates the object in edit mode to change the data, finalizing with a trigger which goes and updates account. Thank you very much for you help. It is much appreciated.