You need to sign in to do that
Don't have an account?
How pass AccountId to Controller from Asset
Hi,
I added a button on Asset tab which will call visualforce page. Inside visualforce page i am calling a apex controller which has a SOQL query based on AccountId
Assets are associted to Account. I am using below method to pass AccountId from Asset Page but its not working. Please suggest me how to change.
public class renewal_Asset
{
public renewal_Asset(ApexPages.StandardController Ast ) {
this();
}
public List<Asset> Ast {get;set;}
public renewal_Asset()
{
String AstId = ApexPages.currentPage().getParameters().get('AccountId');
Ast = [SELECT Name,SerialNumber,Product2Id,SLA_End_Date__c,AccountId
FROM Asset
WHERE Id = :AstId ];
}
}
Thanks
Sudhir
If that works, please don't forget click on 'Best answer' to know that is solved.
Thanks,
Pablo
All Answers
{
this.Ast = Ast;
}
public List<Asset> listAst {get;set;}
public renewal_Asset()
{
String AstId = ApexPages.currentPage().getParameters().get('AccountId');
listAst= [SELECT Name,SerialNumber,Product2Id,SLA_End_Date__c,AccountId
FROM Asset
WHERE Id = :Ast.getId()];
}
}
If that works, please don't forget click on 'Best answer' to know that is solved.
Thanks,
Pablo
I tried below code to fix its working Please check and let me know.
public class renewal_Asset
{
public renewal_Asset(ApexPages.StandardController Ast ) {
this();
}
public List<Asset> Ast {get;set;}
public renewal_Asset()
{
String AstId = ApexPages.currentPage().getParameters().get('Id');
Asset A;
A = [SELECT AccountId FROM Asset WHERE ID = :AstId Limit 1];
Ast = [SELECT Name,SerialNumber,Product2Id,SLA_End_Date__c,AccountId
FROM Asset
WHERE AccountId = :A.AccountId ];
}
}
{
public List<Asset> lstAst {get;set;}
public renewal_Asset()
{
Asset A;
A = [SELECT AccountId FROM Asset WHERE ID = :AstId Limit 1];
if(A != null){
FROM Asset
WHERE AccountId = :A.AccountId ];
}