You need to sign in to do that
Don't have an account?
SFDummy
how do I get ID from salesforce URL in my controller
I am writting a VF page to show custom objects related to account in case.
I need to show in case custom objects related to Case.Account. How can I can get ID from salesforce URL
for example I have the following url and I want to get if id part of the URL
https://na4.salesforce.com/5005000000EEh4t
Thanks for help
You've not stated how your page is being accessed, but I'm inferring that, since you are showing a standard page layout URL that this is a VF page embedded in a page layout.
In Apex, in a custom controller, it should be accessible like this:
But if this is embedded in a page layout then you must be using standard controller. If so, then you just go to the param in the constructor and get a handle to the passed in Standard Controller.
If it is an extension for standard controller, you can just get the case record using this:
You can also get it from your visualforce code by binding to the $CurrentPage global variable in your markup:
Thanks for the response.
I am getting the following error when getting caseID
Illegal assignment from Object to Id at line 25 column 5
I am currently trying to embed a VF Page using Page layout.
However, when i try to access the ID usiing getRecord().get('id), and System.debug the ID, i always get a 'null' value in it
I gathered you mentioned something about using a parm in a constructor. Could you kindly elaborate on that part?
Thanks,
Thanks,
Mahesh
In line 3, you are not casting the Systrm variable type into ID type. You will find the success I believe.
Good luck
Im a salesforce newbie.
Im trying to access ID from a webservice method.
Im calling this method from a custom button on custom page layout.
Im getting SOAP error when i try accessing ID using
ApexPages.currentPage().getParameters().get('id');
Here is my code snippet. and im trying to copy an instance of custom object record into SF standard object using Custom settings.
global with sharing class copyObjCustomSettingsMapping {
webservice static void MapLeadfields() {
string MyLeadid;
Lead LeadObj;
string qry = '';
Map<string, string> MapMappingTable = new map<string,string>();
Savepoint sp = Database.setSavepoint();
try {
LeadObj = new Lead();
MyLeadid = ApexPages.currentPage().getParameters().get('id');
system.debug('Checkpint 0::::recordTypeId::::::'+ MyLeadid);
for (MyLeadToLeadMapping__c mappingTableRec : MyLeadToLeadMapping__c.getall().Values()) {
if (mappingTableRec.Name != null && mappingTableRec.Lead_Field_API_Name__c != Null ) {
MapMappingTable.put(mappingTableRec.Name , mappingTableRec.Lead_Field_API_Name__c);
qry += mappingTableRec.Name + ',';
}
}
qry = 'select ' + qry + 'id FROM My_Lead__c where id ='+ MyLeadid;
system.debug('Checkpint 1::::::::::'+ qry);
My_Lead__c MyLead = Database.query(qry);
for(String sMyLeadField: MapMappingTable.keySet()) {
String sLeadField = MapMappingTable.get(sMyLeadField);
LeadObj.put(sLeadField, MyLead.get(sMyLeadField));
}
LeadObj.OwnerID = UserInfo.getUserId() ;
LeadObj.status='new';
insert LeadObj;
} catch(Exception ex) {
Database.rollback(sp);
}
}
}
Javascript call from custom button
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
var result = sforce.apex.execute("copyObjCustomSettingsMapping", "MapLeadfields",{});
alert(result);
Im always getting a null for the ID which im trying to access in the pagelayout of custom object.
If it is a visualforce page it is a matter a second i can do write code snippet exactly like yours and get the job done..
Appreciate any help.. thanks