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
ManoharSFManoharSF 

Apex syntax

Hi ther,

need help in getting the syntax right for the class.

public class class1{

    public class Result1 
    {
        public Decimal a1{get;set;}
        public Decimal b1{get;set;}
        public Decimal c1{get;set;}
        public Decimal d1{get;set;}
    }

    public Result1 method1 (id recId ) 
    {  
        ... some logic...
        ......

        Result1 r1 = New Result1();
        r1.a1 = some value;
        r1.b1 = some value;
        r1.c1 = some value;
        
        return r1;
    }
}

global class class2{

    global class Result2 
    {
        public Decimal a2{get;set;}
        public Decimal b2{get;set;}
        public Decimal c2{get;set;}
        public Decimal d2{get;set;}
    }

    global Result2 method(){ 

        ... some logic...
        ......

        Result2 r2 = New Result2();

        class1 c1 = new class1();

        **r2 = c1.method1(rid);** <-- How can I get the result1 from method1 and parse it and assign                 it to each variable in r2?

        like r2.a2 = c1.method1(rid).a1;
        like r2.b2 = c1.method1(rid).b1;
        like r2.c2 = c1.method1(rid).c1;

   }
}

 

 

any help is greatly appreciated.

Thanks,
Manohar

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
ManoharSFManoharSF

Thanks for your help,

 

make sense but they were not part of package or namespace but here's how I was able to resolve, hope it will help someone else in future

 

 

public class class1{

    public class Result1 
    {
        public Decimal a1{get;set;}
        public Decimal b1{get;set;}
        public Decimal c1{get;set;}
        public Decimal d1{get;set;}
    }

    public Result1 method1 (id recId ) 
    {  
        ... some logic...
        ......

        Result1 r1 = New Result1();
        r1.a1 = some value;
        r1.b1 = some value;
        r1.c1 = some value;

        return r1;
    }
}

global class class2{

    global class Result2 
    {
        public Decimal a2{get;set;}
        public Decimal b2{get;set;}
        public Decimal c2{get;set;}
        public Decimal d2{get;set;}
    }

    global Result2 method(){ 

        ... some logic...
        ......

        Result2 r2 = New Result2();

        class1 c1 = new class1();
        class1.Result1 r1 = new class1.Result1 ();
        r1 = c1.method1(rid);

        r2.a2 = r1.a1;
        r2.b2 = r1.b1;
        r2.c2 = r1.c1;

   }
}

 

All Answers

sfdcfoxsfdcfox
The problem is that class2 is global, while class1 is public. This only works if class1 and class2 are in the same package. If class1 is in namespace a, and class2 is in namespace b, then class1 can access class2, but class2 cannot access class1. Assuming they are in the same namespace, however, there should be no problem with the syntax you're using.
ManoharSFManoharSF

Thanks for your help,

 

make sense but they were not part of package or namespace but here's how I was able to resolve, hope it will help someone else in future

 

 

public class class1{

    public class Result1 
    {
        public Decimal a1{get;set;}
        public Decimal b1{get;set;}
        public Decimal c1{get;set;}
        public Decimal d1{get;set;}
    }

    public Result1 method1 (id recId ) 
    {  
        ... some logic...
        ......

        Result1 r1 = New Result1();
        r1.a1 = some value;
        r1.b1 = some value;
        r1.c1 = some value;

        return r1;
    }
}

global class class2{

    global class Result2 
    {
        public Decimal a2{get;set;}
        public Decimal b2{get;set;}
        public Decimal c2{get;set;}
        public Decimal d2{get;set;}
    }

    global Result2 method(){ 

        ... some logic...
        ......

        Result2 r2 = New Result2();

        class1 c1 = new class1();
        class1.Result1 r1 = new class1.Result1 ();
        r1 = c1.method1(rid);

        r2.a2 = r1.a1;
        r2.b2 = r1.b1;
        r2.c2 = r1.c1;

   }
}

 

This was selected as the best answer