You need to sign in to do that
Don't have an account?
Cris9931
how to get dynamically the id of an Account when I create a record?
Hi! I want to create a class that will fetch the ID of an Account dynamic when I create a new record. We have a custom object named Account Change request. This object can be found in the related lists from Account. When user press to create a new Account Change Request I want to override it with my visualforce page, thus I would need to display the informations on my VF page from that Account. I tried to create by myself but it's not working..
Account__c is my master-detail with the Account object.. please help.
public class MasterDataChange{ public Account parentAccount{get; set;} public Account_Change_Request__c accChangeRequest; public MasterDataChange(ApexPages.StandardController controller){ String parentAccId = ApexPages.currentPage().getParameters().get('id'); if(parentAccId != null){ parentAccount= [SELECT Id, Name FROM Account WHERE Id = :parentAccId limit 1]; accChangeRequest.Account__c = parentAccount.Id; } } public PageReference save(){ insert accountChangeRequest; PageReference pg = new PageReference('/'+parentAccount.Id); pg.setRedirect(true); return pg; } }
Account__c is my master-detail with the Account object.. please help.
May be you can use retURL instead of ID.
For an example you write something like this in constructor:
Thanks,
Ashish Singh.
Uff.. it's not working...
I think my code is not good at all.. I mean my approach.
my class:
my vf page:
For example it should have a URL created like this once you click on new button:
https://c.ap17.visual.force.com/apex/AccountChangeRequest?CF00N2x000000j7pQ=Dickenson+plc&CF00N2x000000j7pQ_lkid=0012x000002RLD4&scontrolCaching=1&retURL=%2F0012x000002RLD4&sfdc.override=1
here as you can see we have retURL so we can fetch it.
Thanks
Ashish Singh.
Ok, I did exactly the same steps you mentioned. This is my url:
https://sig-cb--full--c.cs88.visual.force.com/apex/testtest1?CF00N5800000Chfhg=PT+SARANA+KARYA+UTAMA&CF00N5800000Chfhg_lkid=0015800000F42aZ&scontrolCaching=1&retURL=%2F0015800000F42aZ&RecordType=01258000000AiQu&ent=01I58000000umn8&save_new=1&sfdc.override=1
it works, I have the ID now stored:
I just added this in my visualforce page
and I can see the ID for the account
Extension:
VF:
Thanks,
Ashish Singh.
However, now my last step is to associate the new record - Account Change Request with the Account and display the fields(prepopulate the fields with the values from Account).... I still have this error:
List has no rows for assignment to SObject
An unexpected error has occurred. Your development organization has been notified.
I modified a bit my class and vf page:
Any idea why I still have that error message? I'm sure I'm clicking from an ACCOUNT and not from anywhere else.
What I'm trying to do here is to display the fields in my visualforce page with the fields prepopulated.
Exactly like this:
And the other thing is where clause of query. Instead of Account__c, its ID.
Oh..Do you know why I cant see my page on the list buttons?
my vf page:
Just for your info when we try to create a list view then we user standardcontroller and recordsetvar, then it will be available in list option.
ah, this is not good.. :( i would need to have the button on my related lists when I access an Account.
With Link and Button how can I display these buttons on my Account page if I create the buttons on my Account Change Request?
take a look here:
These buttons are only visible for LIST Buttons and not Detail Page Button and Detail Page Link....
Okay... I managed to transform my button into a List and i added to related list on my Account.
However now when I press the button I encounter another error:
Why I have this error?
so what changes do I have to make in my class?
I need to query the recordtypeid as well?
These are my record types for the ACR. So when I press my button and visualforce shows up I want to always be 'Master Data Change'.