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
motti10motti10 

How do I pass an Asset Name (I selected) to a controller on a different page

I created a custom TAB which loads a list of Assets on an ApexPage. I click on the Asset Name and now want to send the Asset name I clicked to my Controller so that I can do :queries like:

 

Asset myasset = SELECT name from Asset where name = :[CLICKED ASSET NAME TEXT]

 

How can I retrieve the AssetName so I can you it in my controller?

 

BTW I have enhanced list to view Assets on page

 

Thank you

Blue LionBlue Lion

Instead of using Enhanced List, we tried listing all the fields separately using Outputtext.

In that, use the below code to pass the parameter to another page.

<apex:outputLink value="L2"> {!l.Name} <apex:param name="LId" value="{!l.Id}"/> </apex:outputLink>

 

 

Then use the below code in the next page to accept the parameter using Attribute Name

<apex:attribute name="LId" type="Id" description="TODO: Describe me"/>

 

Then you can get the parm value inside the class using the below code

Id Lead_Id = ApexPages.currentPage().getParameters().get('LId');

 

Thanks,

Revathy

Blue Lion

motti10motti10

Hi Revathy

 

Still no luck

 

Here is my source code

 

I have a TAB names ASSETS which list the Assets 

This page has APex code (below)(

 

When I click on an Asset in the list, I am taken to an ASSET DETAILS page

As you can see In the controller I am doing REST calls to retrive data, so I need to pass in the Asset NAME I selected  

 




APEXPAGE

 

<apex:page Controller="callAxedaREST" id="thePage" action="{!getData}" >
<apex:pageBlock title="Axeda Assets" >
<apex:image id="theImage" value="{!$Resource.AxedaLogo}" width="210" height="62"/>
<apex:ListViews type="Asset" id="AssetList" />
 <apex:ListViews type="Case" id="CaseList" />
</apex:pageBlock>
</apex:page>

 

CONTROLLER

 

public class callAxedaREST{

public String getAssetList() {
return null;
}


public String getL() {
return null;
}


public String l { get; set; }
public String Asset { get; set; }

public String Assets { get; set; }

public PageReference someAction() {
return null;
}

public String AssetName { get; set; }
public List<Asset> theAssets { get; set; }

private string action;
private string session;
private string result;
private string var;
private string alarm;
private string diname;

private string firmware;

public callAxedaREST() {


}

public void getData() {

http h = new http();
final string baseUrl = 'https://[someURL]/services/v1/rest/Scripto/execute/testMT?username=user&password=passw';

httprequest req = new httprequest();
req.setEndpoint(baseUrl);
req.setMethod('GET');
string json;

httpresponse res = h.send(req);
result = res.getBody().replace('\n', '');

JSONObject jobj = new JSONObject(result);
var = toGetResult(jobj).toDisplayString();
diname = toGetResult(jobj).toDisplayString2();

}

public string getResult() {
return this.var;
}



public GetResult toGetResult(JSONObject resp) {

GetResult get = new GetResult();
Asset myasset = [SELECT name from Asset where name ='First Asset'];  -> Needs replacement for selected AssetNAme
myAsset.Firmware__c = resp.getValue('firmware').str;

try
{
update myAsset;
}
catch(exception e)
{
throw e;
}

return get;
}

public class GetResult {

public Set<string> keys;

public String name;
public String severity;
public String diname;

public String toDisplayString() {
return name ;
}

public String toDisplayString2() {
return 'Firmware' ;
}
}
}