You need to sign in to do that
Don't have an account?
vw
method does not exist or incorrect signature when calling public method
Hi there, I've created a public class called SponsorshipMaintenance that has a public method UpdateSponsorshipCountry. Looks like this:
public class SponsorshipMaintenance {
public void UpdateSponsorshipCountry(List<Sponsorship__c> Sponsorships, List<Id> ChildIds){
// .... some code here
}
}
The class compiles with no errors. When I try to compile a trigger that has a call to the UpdateSponsorshipCountry method, I get the message "method does not exist or incorrect signature" on the line that calls the method. The trigger looks like this:
trigger SponsorshipSetCountry on Sponsorship__c (before insert, before update) {
//get list of sponsored child Ids of new sponsorships
Id[] SponsoredKids = new Id[]{};
for (Sponsorship__c spons : Trigger.new){
SponsoredKids.add(spons.Child__c);
}
//call method to set the correct country on the sponsorship objects
SponsorshipMaintenance.UpdateSponsorshipCountry(Trigger.New,SponsoredKids); //this is the line that's generating the error. If I comment it out, the trigger compiles.
}
Any guidance would be most appreciated. Thank you!
public class SponsorshipMaintenance {
public void UpdateSponsorshipCountry(List<Sponsorship__c> Sponsorships, List<Id> ChildIds){
// .... some code here
}
}
The class compiles with no errors. When I try to compile a trigger that has a call to the UpdateSponsorshipCountry method, I get the message "method does not exist or incorrect signature" on the line that calls the method. The trigger looks like this:
trigger SponsorshipSetCountry on Sponsorship__c (before insert, before update) {
//get list of sponsored child Ids of new sponsorships
Id[] SponsoredKids = new Id[]{};
for (Sponsorship__c spons : Trigger.new){
SponsoredKids.add(spons.Child__c);
}
//call method to set the correct country on the sponsorship objects
SponsorshipMaintenance.UpdateSponsorshipCountry(Trigger.New,SponsoredKids); //this is the line that's generating the error. If I comment it out, the trigger compiles.
}
Any guidance would be most appreciated. Thank you!
public static void UpdateSponsorshipCountry(List<Sponsorship__c> Sponsorships, List<Id> ChildIds) {
....
}
Or you need to create an instance of your class, like this:
//Create the instance
SponsorshipMaintenance sm = new SponsorshipMaintenance();
//Call the method
sm.UpdateSponsorshipCountry(Trigger.New,SponsoredKids);
All Answers
public static void UpdateSponsorshipCountry(List<Sponsorship__c> Sponsorships, List<Id> ChildIds) {
....
}
Or you need to create an instance of your class, like this:
//Create the instance
SponsorshipMaintenance sm = new SponsorshipMaintenance();
//Call the method
sm.UpdateSponsorshipCountry(Trigger.New,SponsoredKids);
Thanks
apex class
public static class property_class
{
public static void applyDiscount(List<Property__c> NewHousesList)
{
for(Property__c p :NewHousesList) {
if(p.Type__c == 'vila'){
p.Pricer__c = p.Pricer__c - (p.Pricer__c x 0.05);
}
}
}
}
//TRIGGER
trigger discount_trigger on Property__c(Before Insert)
{
property_class.applyDiscount(trigger.new);
}
FACING SAME ISSUE MENTIONED ABOVE ,METHOD DOES NOT EXITS OR NO SIGNATURE .
PLEASE HELP
have you fixed the issue? if yes please post the solution I am also dealing with same.
try this code
In Apex you can't define a class as Static.
public class AccountProcessor {
@future public static void countContacts(Set<id> setId){
List<Account> lstAccount = [select id,Number_of_Contacts__c ,
(select id from contacts ) from account where id in :setId ];
for( Account acc : lstAccount ) { List<Contact> lstCont = acc.contacts ;
acc.Number_of_Contacts__c = lstCont.size(); } update lstAccount;
}
}
----------------------------------------------------------
@IsTest
public class AccountProcessorTest {
public static testmethod void TestAccountProcessorTest() {
Account a = new Account(); a.Name = 'Test Account';
Insert a; Contact cont = New Contact();
cont.FirstName ='Bob';
cont.LastName ='Masters';
cont.AccountId = a.Id;
Insert cont; set<Id> setAccId = new Set<ID>();
setAccId.add(a.id);
Test.startTest();
AccountProcessor.countContacts(setAccId);
Test.stopTest();
Account ACC = [select Number_of_Contacts__c from Account where id = :a.id LIMIT 1];
System.assertEquals ( Integer.valueOf(ACC.Number_of_Contacts__c) ,1);
}
}