I have a vf page that accepts few url query parameters. When a submit button is clicked, the apex controller takes the parameter and depending upon the parameter values different sorts of SOQL and DML operation are performed.

The url parameters are not stored in the database. Now, this whole process is UI specific (i.e. only works for visualforce).

We now want the same functionality in Lightning as well but instead of writing same code twice, we want to move all the changes to trigger.

Now, In trigger how do i deal with query parameters that are send in the url? Is there any pattern that could be used in such situation?


I know you say that you want to move this code into a trigger, but my intuition would be to create a @AuraEnabled method on the current apex controller, separate out the code that calls the soql/dml and then call that code from either the controller constructor or from the @AuraEnabled method.

For example: Apex:

public class sotestcontroller {
    public Account act {get; set;}

    public sotestcontroller(){
        Id actId = ApexPages.currentPage().getParameters().get('actId');
        this.act = getAccount(actId);
    private static Account getAccount(Id actId){
        Account[] ActList= [SELECT name FROM Account WHERE id =:actId];
        if(ActList.size() > 0){
            return actList[0];
        return null;

    public static Account getAccountJS(String actId) {
        Account act = getAccount(actId);
        return act;


<apex:page controller="sotestcontroller" id="pageid">
    {! Act.Name }

Aura Cmp:

<aura:component implements="flexipage:availableForAllPageTypes" controller="sotestcontroller">
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>
    <aura:attribute name="actName" type="String" default=""/>

    {! v.actName }

Aura controller

    init : function(component, event, helper) {

    let url = new URL(document.URL);
    let actId = url.searchParams.get("actId");
    let action = component.get("c.getAccountJS");
    action.setParams({'actId': actId});
    action.setCallback(this, function(response) {
    let actName = response.getReturnValue().Name;
    component.set("v.actName", actName);

Otherwise, I could be wrong, but I think you could use a static variable to pass the data into the trigger.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.