Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
ShowAll Questionssorted byDate Posted

# Lsit of decimal

List<Decimal> cal =new List<Decimal>();
public decimal fun(){
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 R

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(){
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(){
return cal;
}```
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 Aslam

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

Hope this will be resolve the issue.

Please mark it as the best answer if it helps.

Thanks

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);
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;
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.
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 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);
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;