You need to sign in to do that
Don't have an account?

Button to update child accounts on case
Hello everybody,
I'd like to know if it's possible to create a button on cases that open new window which list all child accounts related to case's account ?
And after to select any accounts, I need to update a field in these accounts.
Thanks for your answers
Thomas
I'd like to know if it's possible to create a button on cases that open new window which list all child accounts related to case's account ?
And after to select any accounts, I need to update a field in these accounts.
Thanks for your answers
Thomas
Thanks,
Amit
All Answers
Hi Thomas,
Yes, it is possible you can create a custom button which will open a VF page. For this, you need to use the concept of the wrapper class.
For detailed information visit the given link.
http://www.sfdcpoint.com/salesforce/wrapper-class-in-apex/
Hope this helps for you :)
Thanks,
Amit Singh.
Thomas
I try the code you send to me and I need you help for two things :
- I build a button on case layout and I just need to see when I click on this button the account related to this case and his childs accounts (based on the hierarchy)
- Second thing, when I click on the button on screenshot, I want to update a case lookup field on all accounts selected pages.
Thanks
Thomas
If you do not mind will you please be more specific on your requirement. What you want yo achieve?
1 - You want to show the list of All account and it's Chile accounts related to the Case?
2 - Please elaborate more this.
1- Yes exactly, I need to have a button on case layout which list the account related to this case and all his childs accounts.
2- Yes sure : when I have this list, I need to select accounts that I want and then when I click on the button (on visualforce page), I need to update a lookup field related to all accounts selected.
Tell me if it's not clear.
Thomas
Do you have any lookup field in Account OBJECT which you need to update with Case ID?
Also, please share your apex class so that I could help and modify the class.
Thanks :)
Amit Singh.
Sure this my visualforce page :
<apex:page Controller="AccountSelectClassController" sidebar="false">
<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID){
var inputCheckBox = document.getElementsByTagName("input");
for(var i=0; i<inputCheckBox.length; i++){
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
inputCheckBox[i].checked = obj.checked;
}
}
}
</script>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Update Contract Termination Case" action="{!processSelected}" rerender="table2"/>
</apex:pageBlockButtons>
<apex:pageblockSection title="All Accounts" collapsible="false" columns="2">
<apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" id="table" title="All Accounts">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
</apex:facet>
<apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
</apex:column>
<apex:column value="{!accWrap.acc.Name}" />
<apex:column value="{!accWrap.acc.BillingState}" />
<apex:column value="{!accWrap.acc.Phone}" />
</apex:pageBlockTable>
<apex:pageBlockTable value="{!selectedAccounts}" var="c" id="table2" title="Selected Accounts">
<apex:column value="{!c.Name}" headerValue="Account Name"/>
<apex:column value="{!c.BillingState}" headerValue="Billing State"/>
<apex:column value="{!c.Phone}" headerValue="Phone"/>
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
and the class :
public class AccountSelectClassController{
public AccountSelectClassController(ApexPages.StandardController controller) {
}
//Our collection of the class/wrapper objects wrapAccount
public List<wrapAccount> wrapAccountList {get; set;}
public List<Account> selectedAccounts{get;set;}
public AccountSelectClassController(){
if(wrapAccountList == null) {
wrapAccountList = new List<wrapAccount>();
for(Account a: [select Id, Name,BillingState, Website, Phone from Account limit 10]) {
// As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
wrapAccountList.add(new wrapAccount(a));
}
}
}
public void processSelected() {
selectedAccounts = new List<Account>();
for(wrapAccount wrapAccountObj : wrapAccountList) {
if(wrapAccountObj.selected == true) {
selectedAccounts.add(wrapAccountObj.acc);
}
}
}
// This is our wrapper/container class. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value
public class wrapAccount {
public Account acc {get; set;}
public Boolean selected {get; set;}
public wrapAccount(Account a) {
acc = a;
selected = false;
}
}
}
Have you tried your code for your logic?
Also, I have made some tweaks on VF page and Apex Class use the below code and use code snippet for pasting the code for increasing the readability of the code.
VF Page code:
Apex Class: Use the above code and let me know the outcomes :)
Thanks,
Amit
And at line 13 of your class you forgot a WHERE attribute :)
Thomas
e
Thanks,
Amit
Thanks
Thomas
Use below code
This must do the trick :)
Thanks
let me know if this makes sense OR elaborate more on your point.
Thanks.
Thanks,
"TEST" is the name of my visualforce page.
Sorry Amit I'm novice on apex :)
Thomas
1 - Setup -> Case -> Button, Links and Action -> Create Button or Link.
2 - Give Name and Label of the button.
3 - Select Detail page button for "Display Type".
4 - You can adjust height and width of VF page as per your requirement. 5 - Got to case layout and add the button you created on the detail page.
Also, modify the VF page as per given.
Hope this will help :)
Thanks,
Amit.
Thanks Amit
Thomas
Thanks :)
Thanks :)
Hi Amit,
Sorry for yesterday, I left my desk :)
I tried your code but I have an error line 6 : Error: Compile Error: unexpected token: 'if' at line 6 column 8
Thomas
Thanks,
Amit
Thanks
I let you know if i need something else
Thomas