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
Himanshu Patel 55Himanshu Patel 55 

Error while Apex class

Hi, 

I am trying to call Apex Class from Trigger and getting error 'Method does not exist or incorrect signature'. How should i call constructor in Trigger. 

trigger Accountrigger on Account (before update) {
             if(Trigger.Isupdate && Trigger.IsBefore)
    {  
            for (Account Acc:Trigger.new)
            {
              SenddataRequest();
              }
    }      
}

Below is Apex Class
public class SenddataRequest {

    public class requestWrapper

{-----Code-----    }
        
    public String GetAccounts(Account a)

    { -----Code----      }
    

public SenddataRequest(){
      ----- Code-------------        
}
        
    }

}



 
CharuDuttCharuDutt
Hii Himanshu Patel
Try Below Code
trigger Accountrigger34234323 on Account (before update) {
             if(Trigger.Isupdate && Trigger.IsBefore)
    {  
            for (Account Acc:Trigger.new)
            {
              SenddataRequest sdr = new SenddataRequest();
                
              }
    }      
}
Please Mark it As Best Answer If It Helps
Thank You!

 
mukesh guptamukesh gupta
Hi Himanshu,

Please use SIngleton Design Pattern for your requirment as below:-
 
trigger Accountrigger on Account (before update) {
             if(Trigger.Isupdate && Trigger.IsBefore)
    {  
            for (Account Acc:Trigger.new)
            {
              SenddataRequest sndObj = SenddataRequest.getInstance();
              }
    }      
}
 
public class SenddataRequest {

private static SenddataRequest instance = null;
public String Id {get; set;} 
    public class requestWrapper
	{


	}
        
    public String GetAccounts(Account a)
    {

	}
	
	private SenddataRequest(){
	// id = /*find your record type Id     */ 
	}
    
   private static SenddataRequest getInstance(){
         
    if(instance == null){
	  instance = new SenddataRequest();
	} 
		return instance;
	 }
        
    }

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 



 
Himanshu Patel 55Himanshu Patel 55
Hi Mukesh,  

I have made changes and getting error in Trigger
Method is not visible: SenddataRequest.getInstance()
 
Suzanne ShanksSuzanne Shanks
Get the complete information for the "Epson 0xf1" error and know how to fix the problem on your printer. Because the error related to the software/hardware on your PC/printer both.
Suraj Tripathi 47Suraj Tripathi 47
Hi,

Please made your method public.

Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi

 
mukesh guptamukesh gupta
Hi Himanshu,

Please  update in Apexclass last function public instead of private 
 
public static SenddataRequest getInstance(){
         
    if(instance == null){
	  instance = new SenddataRequest();
	} 
		return instance;
	 }

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh  
Himanshu Patel 55Himanshu Patel 55
Thanks Mukesh, I have marked it Public which allowed me to Save Trigger. However i am getting Call out error now. 
'Callout from triggers are currently not supported' error
When i am trying to do  @future (callout=true), it's not allowing. Do you know what's best way to do @Future with Constructor. 
Himanshu Patel 55Himanshu Patel 55
I need to do Call out because Apex class is trying to connect external endpoint as REST API which is mentioned in Consturctor "private SenddataRequest()"
PINKY REGHUPINKY REGHU
Hi Himanshu,
 
public class SenddataRequest {
    
    public class requestWrapper
    {  }
    
    public String GetAccounts(Account a)
    {  return 'Hello'; }
    
    public SenddataRequest(){
        makeCallouts();
    }
    

@future(callout=true)
public static void makeCallouts()
{
    system.debug('Called makecallouts method');
}

}

Please mark it as Best Answer if it helps you.