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
OneMeggittOneMeggitt 

Newby Question on APEX

 

OK. I am new to this, but am missing something dumb. I know.

 

Class is ScottClass

 

I want to make a method that performs an account merge function.

Basically, I have two different fields on Accounts with the same number in it. I want to pull them together and merge them.

I can do it one by one, but I'm trying to make it a method.  I know it should be possible.

 

public class ScottClass {

public void mergeBasing (string ERPSTring){
Account masterAcct = [SELECT Id, SAPCIBER__c FROM Account WHERE SAPCIBER__c = :ERPString LIMIT 1];
Account mergeAcct = [SELECT Id, ERPBasing_C__c FROM Account WHERE ERPBasing_C__c = :ERPString LIMIT 1];
merge masterAcct mergeAcct;
}
}
ScottClass.mergeBasing('6763');

 

-------------- I know the queries are right, because I know this works:

public String ERPString = '14138';
Account masterAcct = [SELECT Id, SAPCIBER__c FROM Account WHERE SAPCIBER__c = :ERPString LIMIT 1];
Account mergeAcct = [SELECT Id, ERPBasing_C__c FROM Account WHERE ERPBasing_C__c = :ERPString LIMIT 1];
try {
merge masterAcct mergeAcct;
} catch (DmlException e) {
// Process exception here
}

Vinit_KumarVinit_Kumar

The code seems fine.What is the error you are getting ??

zettahertzzettahertz

Are you getting an error in your code when you're calling the method? Or the merge is just not happening?
I suspect that you're probably getting this:
"Method does not exist or incorrect signature:"

I notice that your method call looks like a static method call
ClassName.method();

If you want to do that, you need to make your mergeBasic method static:

public static void mergeBasing (string ERPSTring){

}

 

Otherwise you'd need to instantiate a new instance of the object ScottClass:

ScottClass myClass = new ScottClass();

myClass.mergeBasing('1234');

Unless you instantiated it by making it ScottClass ScottClass = new ScottClass();
(This is not exactly a good practice due to naming convention because instance/variables should start with lower case, whereas Classes should be upper case and usually shouldn't be the same name as the Class/Object)

 

Link about the static keyword:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_static.htm

 

 

OneMeggittOneMeggitt
line 8, column 1: Method does not exist or incorrect signature: ScottClass.mergeBasing(String)
OneMeggittOneMeggitt

OK.

 

The post above was for the error I received. Good guess on the error message.  

Now, when I make it static, I see:

line 2, column 21: Only top-level class methods can be declared static

 

Which I need to read up on.

 

Thanks all. 

zettahertzzettahertz

That's most likely caused by the ScottClass being an inner class

 

Something like:

public class OuterClass {

   public class ScottClass{

   }

}

 

Static can only be used on the OuterClass