You need to sign in to do that
Don't have an account?
abhi patil
Illegal assignment from Integer to date?
public void newinsert(string oppName, date newd){
Opportunity opp = new opportunity();
opp.Name = oppName;
opp.Amount= 344556;
opp.CloseDate= newd;
insert opp;
Opportunity opp = new opportunity();
opp.Name = oppName;
opp.Amount= 344556;
opp.CloseDate= newd;
insert opp;
In anonymous window execute the code below.
=====================================
public void newinsert(string oppName, date newd){
Opportunity opp = new opportunity();
opp.Name = oppName;
opp.Amount= 344556;
opp.CloseDate= newd;
opp.StageName = 'Prospecting';
insert opp;
system.debug('opp id' + opp.id);
}
newinsert('Test1', System.today());
======================================
The error "Illegal assignment from Integer to date" occurs because you are trying to assign an Integer value to a Date field.
In your code snippet, the newd parameter is of type date, which represents a specific date. However, when assigning the value to the CloseDate field of the Opportunity object, it seems that you are passing an Integer value instead of a valid date.
To fix this issue, make sure that the newd parameter is passed as a valid Date object.
Ensure that when calling the newinsert method, you provide a valid Date value for the newd parameter.
example:
If this information helps, please mark the answer as best. Thank you
To fix this issue, you need to make sure that the variable newd is of the correct data type, which should be Date. Here's the corrected code:
In this corrected code, I assumed that Opportunity is a custom class with properties such as Name, Amount, and CloseDate. Also, make sure that you have imported the java.util.Date class at the top of your file.
I hope this will help you.and also check this: az 300 training (https://www.igmguru.com/cloud-computing/microsoft-azure-solution-architect-az-300-training/)
Hi abhi patil,
Please go through the below modified code:
Hope it helps.
Thanks!