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
Vadivel MuruganVadivel Murugan 

Lsit of decimal

List<Decimal> cal =new List<Decimal>();
public decimal fun(){
cal.add(0.0);
cal.add(0.1);
return cal;  // This is possible, But when I have to return that time to display error: "Return value must be of type: Decimal at line"
}

If any one know how to return the list decimal value into function.
Arunkumar RArunkumar R
Hi Vadivel, 

Since your method returning just Decimal, NOT List<Decimal>. Based on you need you can alter the below suggested codes,
 
List<Decimal> cal =new List<Decimal>();
public decimal fun(){
cal.add(0.0);
cal.add(0.1);
return cal[0]; // Here you can return any one of decimal value by referring list   
index.
}
OR Change your method to return type from Decimal to List<Decimal>
List<Decimal> cal =new List<Decimal>();
public List<decimal> fun(){
cal.add(0.0);
cal.add(0.1);
return cal; 
}
Vadivel MuruganVadivel Murugan
When i have change this to display error: Compile Error: Incompatible element type List<Decimal> for collection of Decimal at line 116 column 19
Usman AslamUsman Aslam
@Vadivel -

You can try this:
List<Decimal> cal =new List<Decimal>(); // if cal is an instance variable
public List<Decimal> fun(){
    cal.add(0.0);
    cal.add(0.1);
    return cal;  
}
OR
public List<Decimal> fun(){
    List<Decimal> cal =new List<Decimal>();
    cal.add(0.0);
    cal.add(0.1);
    return cal;  
}
OR
List<Decimal> cal =new List<Decimal>(); // if cal is an instance variable
public void fun(){
    cal.add(0.0);
    cal.add(0.1);
}

Hope this will be resolve the issue.

Please mark it as the best answer if it helps.

Thanks

 
Vadivel MuruganVadivel Murugan
List<Decimal> salePrice = new List<Decimal>();
private Decimal scenario4(Id ssVar1Id){
        if(mapServiceSheetIdVisitRecord.get(ssVar1Id).Priority__c == '4 Hour Corrective'){
            if(!isOutOfMonFri830AMto5PM){
                System.debug('####'+'Sce 4: Pri=4C,Dep Time : Inside Office Hours');
                salePrice.add(insideOfficeHoursPri4CSce4(ssVar1Id)); // This call another mathod
            }
return salePrice; // Here Error is Occured.
}

private Decimal insideOfficeHoursPri4CSce4(Id ssVar1id){
        System.debug('####'+'Sce 4: Pri=4C,Dep Time : Inside Office Hours:BEGIN');
        System.Debug('####List Of Split Hours is'+listOfSplitHoursSpent);
        If(listOfSplitHoursSpent.size() > 1){
        noOfHoursInOfficeTime=listOfSplitHoursSpent.get(0);
        noOfHoursOutOfficeTime = listOfSplitHoursSpent.get(1);
        noOfHoursInOfficeTimeAgain = listOfSplitHoursSpent.get(2);}
        callOutCharge4HourResponse = (mapServiceSheetIdSiteContractRecord.get(ssVar1id)).X4_Hour_Reactive_Call_Out_Charge__c;
        labourChargePerHour=(mapServiceSheetIdSiteContractRecord.get(ssVar1id)).Labour_Charge__c;
        if(callOutCharge4HourResponse==null){
            System.debug('####callOutCharge4HourResponse is Null, Hence Substituted by 0');
            callOutCharge4HourResponse=0.0;
        }
        if(labourChargePerHour==null){
            System.debug('####labourChargePerHour is Null, Hence Substituted by 0');
            labourChargePerHour=0.0;
        }
        salePrice1 = callOutCharge4HourResponse +(labourChargePerHour*noOfHoursInOfficeTime);
        Calloutcharge = callOutCharge4HourResponse;
        Labourcharge = labourChargePerHour*noOfHoursInOfficeTime;
        salePrice.add(salePrice1);
        salePrice.add(Calloutcharge);
        salePrice.add(Labourcharge);
        System.debug('####'+'Sce 4: Pri=4C,Dep Time : Inside Office Hours:END');
        System.debug('####'+'Sce 4: Pri=4C,Dep Time : Inside Office Hours:SALEPRICE'+salePrice);
        return salePrice;
    }

This is my code.
Vadivel MuruganVadivel Murugan
When i have to chane this to display error: Error: Compile Error: Incompatible element type List<Decimal> for collection of Decimal at line 116 column 19
Arunkumar RArunkumar R
In your secod method you are returning decimal instead of list. I have updated your code, please try the below code, let me know if you still face issue.
 
List<Decimal> salePrice = new List<Decimal>();
private List<Decimal> scenario4(Id ssVar1Id){
        if(mapServiceSheetIdVisitRecord.get(ssVar1Id).Priority__c == '4 Hour Corrective'){
            if(!isOutOfMonFri830AMto5PM){
                System.debug('####'+'Sce 4: Pri=4C,Dep Time : Inside Office Hours');
                insideOfficeHoursPri4CSce4(ssVar1Id); 
            }
return salePrice; 
}

private List<Decimal> insideOfficeHoursPri4CSce4(Id ssVar1id){
        System.debug('####'+'Sce 4: Pri=4C,Dep Time : Inside Office Hours:BEGIN');
        System.Debug('####List Of Split Hours is'+listOfSplitHoursSpent);
        If(listOfSplitHoursSpent.size() > 1){
        noOfHoursInOfficeTime=listOfSplitHoursSpent.get(0);
        noOfHoursOutOfficeTime = listOfSplitHoursSpent.get(1);
        noOfHoursInOfficeTimeAgain = listOfSplitHoursSpent.get(2);}
        callOutCharge4HourResponse = (mapServiceSheetIdSiteContractRecord.get(ssVar1id)).X4_Hour_Reactive_Call_Out_Charge__c;
        labourChargePerHour=(mapServiceSheetIdSiteContractRecord.get(ssVar1id)).Labour_Charge__c;
        if(callOutCharge4HourResponse==null){
            System.debug('####callOutCharge4HourResponse is Null, Hence Substituted by 0');
            callOutCharge4HourResponse=0.0;
        }
        if(labourChargePerHour==null){
            System.debug('####labourChargePerHour is Null, Hence Substituted by 0');
            labourChargePerHour=0.0;
        }
        salePrice1 = callOutCharge4HourResponse +(labourChargePerHour*noOfHoursInOfficeTime);
        Calloutcharge = callOutCharge4HourResponse;
        Labourcharge = labourChargePerHour*noOfHoursInOfficeTime;
        salePrice.add(salePrice1);
        salePrice.add(Calloutcharge);
        salePrice.add(Labourcharge);
        System.debug('####'+'Sce 4: Pri=4C,Dep Time : Inside Office Hours:END');
        System.debug('####'+'Sce 4: Pri=4C,Dep Time : Inside Office Hours:SALEPRICE'+salePrice);
        return salePrice;
    }

 
Vadivel MuruganVadivel Murugan
Thank U, Its working