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
sfadm sfadmsfadm sfadm 

How to invoke controller setter method in trigger beforeInsert()?

I have a custom VF page:
<apex:page standardController="Lead" extensions="LeadDuplicateController" tabStyle="Lead"> 
  <apex:pageBlock >
        <apex:pageBlockSection title="Lead Information">
            <apex:outputText value="{!plainHTML}" escape="false" />
        </apex:pageBlockSection>
  </apex:pageBlock>
</apex:page>

AND That is the controller class to the VF page:
 
public with sharing class LeadDuplicateController {

    Lead objLead;

    public String plainHTML { get; set; }

    public LeadDuplicateController(ApexPages.StandardController controller) {
        objLead = (Lead)controller.getRecord();
    }
}
How to invoke the setter method of plainHTML in beforeInsert() method?

The issue I strive to solve is that beforeInsert() method is in another class.
 
Raj VakatiRaj Vakati
Change your controller method as 
 
public with sharing class LeadDuplicateController {

    Lead objLead;

    public String plainHTML { get; set; }

 public LeadDuplicateController() { 
 }

    public LeadDuplicateController(ApexPages.StandardController controller) {
        objLead = (Lead)controller.getRecord();
    }
}

Then call this using the zero agr method  like below .. 
 


LeadDuplicateController  l = new LeadDuplicateController (); 
l.plainHTML ; 




Can you please explan why do you want to call the VF controller code in trigger .. if you want to reuse the code between controller and trigger use helper and handler patterns and reuse the code