You need to sign in to do that
Don't have an account?
Coolday
Why am I getting this error "Illegal assignment from List<Id> to Id"
Can anyone tell me why I am getting this error in my code -
Illegal assignment from List<Id> to Id -(on this line)
Opportunity opp = new Opportunity(Id = Ids);
Apex class -
@InvocableMethod
public static void amount(List<Id> Ids){
Account acc = [SELECT Email__c FROM Account WHERE Id IN (SELECT AccountId from Opportunity WHERE Id =:Ids)];
HTTP http = new HTTP();
HTTPRequest request = new HTTPRequest();
List<Amount__c> listCS = Amount__c.getall().values();
if (listCS != null && listCS.size() > 0) {
String endp = listCS[0].endpoint__c+acc.Email__c;
String auth = listCS[0].auth__c;
String authorizationHeader = 'Basic '+ auth;
request.setHeader ('Authorization', authorizationHeader);
request.setEndpoint (endp);
request.setMethod ('GET');
request.setHeader ('Content-Type', 'application/json; charset=utf-8');
HTTPResponse response = http.send(request);
if(response.getStatusCode() == 200){
system.debug('The Response Body: '+response.getBody());
Map<String, Object> deserializedPayload = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
Decimal tax = (Decimal)deserializedPayload.get('tax');
Opportunity opp = new Opportunity(Id = Ids);
opp.tax__c = tax;
update opp;
} } }
Illegal assignment from List<Id> to Id -(on this line)
Opportunity opp = new Opportunity(Id = Ids);
Apex class -
@InvocableMethod
public static void amount(List<Id> Ids){
Account acc = [SELECT Email__c FROM Account WHERE Id IN (SELECT AccountId from Opportunity WHERE Id =:Ids)];
HTTP http = new HTTP();
HTTPRequest request = new HTTPRequest();
List<Amount__c> listCS = Amount__c.getall().values();
if (listCS != null && listCS.size() > 0) {
String endp = listCS[0].endpoint__c+acc.Email__c;
String auth = listCS[0].auth__c;
String authorizationHeader = 'Basic '+ auth;
request.setHeader ('Authorization', authorizationHeader);
request.setEndpoint (endp);
request.setMethod ('GET');
request.setHeader ('Content-Type', 'application/json; charset=utf-8');
HTTPResponse response = http.send(request);
if(response.getStatusCode() == 200){
system.debug('The Response Body: '+response.getBody());
Map<String, Object> deserializedPayload = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
Decimal tax = (Decimal)deserializedPayload.get('tax');
Opportunity opp = new Opportunity(Id = Ids);
opp.tax__c = tax;
update opp;
} } }
The variable Ids is List<Id> but in the below line you are assiging list <ids> to single id which is causing the issue.
You need assign each id in the llist to opportuntiyid or if you feel the list will only have one Id then change the code as below.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
The variable Ids is List<Id> but in the below line you are assiging list <ids> to single id which is causing the issue.
You need assign each id in the llist to opportuntiyid or if you feel the list will only have one Id then change the code as below.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
An Apex error occurred: System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out using invocable method
Please find the below SSE answer for the similar issue.
https://salesforce.stackexchange.com/questions/115143/api-callout-apex-class-from-workflow-you-have-uncommitted-work-pending-pleas
Thanks,
I have tried the above solution but I cannot figure out this error in my debug logs -
Future method cannot be called from a future or batch method: ClassName.AmountCalloutAsync(List<Id>)
My Apex Class -
@InvocableMethod
public static void amount(List<Id> Ids){
doAmountCalloutAsync(Ids);
}
@future(callout=true)
public static void AmountCalloutAsync(List<Id> Ids){
Account acc = [SELECT Email__c FROM Account WHERE Id IN (SELECT AccountId from Opportunity WHERE Id =:Ids)];
HTTP http = new HTTP();
HTTPRequest request = new HTTPRequest();
List<Amount__c> listCS = Amount__c.getall().values();
if (listCS != null && listCS.size() > 0) {
String endp = listCS[0].endpoint__c+acc.Email__c;
String auth = listCS[0].auth__c;
String authorizationHeader = 'Basic '+ auth;
system.debug('--Authorization : '+authorizationHeader);
request.setHeader ('Authorization', authorizationHeader);
request.setEndpoint (endp);
request.setMethod ('GET');
request.setHeader ('Content-Type', 'application/json; charset=utf-8');
HTTPResponse response = http.send(request);
system.debug('--response : '+response.getBody());
if(response.getStatusCode() == 200){
system.debug('The Response Body: '+response.getBody());
Map<String, Object> deserializedPayload = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
Decimal balance = (Decimal)deserializedPayload.get('balance');
Opportunity opp = new Opportunity(Id = Ids[0]);
opp.tax__c = tax;
update opp;
} }}
Added this condition
if(!System.isFuture())
Thanks for the help!!