Hi i am trying to convert Lead into account and contact but this code convert only into contact and also don't deleted from lead please help.
Thank in advance.
public class ConvertLead {
public ConvertLead()
{
System.debug('convert lead called');
Lead myLead = [SELECT Id FROM Lead WHERE FirstName = 'John'];
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(myLead.id);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
System.debug('converted');
}
}
Your code is working fine, I've executed it anonymously from developer console
I have the following lead from default data which has been provided by SF for developer org:
I've run your code from developer console for lead with name 'Bertha' the result was as following
So, please check the environment for things which might block conversion
Related
I'm creating a method for logging in to MS Dynamics 365 and get the error below when RUN the test:
AADSTS90100: login parameter is empty or not valid.
Here is my code:
public void Login(SecureString login, SecureString password)
{
_driver.Url = "https://{domain}.crm4.dynamics.com/";
_driver.WaitForPageToLoad(TimeSpan.FromSeconds(10));
var userNameInput = _driver.WaitUntilAvailable(By.CssSelector("input[type = 'email']"),
TimeSpan.FromSeconds(10));
userNameInput.SendKeys(login.ToUnsecureString());
var submitButton = _driver.WaitUntilClickable(By.CssSelector("input[type = 'submit'][value =
'Next']"), TimeSpan.FromSeconds(10));
submitButton.Click();
//userNameInput.SendKeys(Keys.Enter);
// following actions
}
I also tried sending the Enter key and Submit() method but no luck.
Interesting thing - I cannot reproduce the issue manually or when DEBUG the test. The error appears only in the RUN mode of the test.
I compared URLs in RUN and DEBUG modes and there is not any difference.
I spent 3 hours in Google but didn't find a solution.
It should be mentioned, that I'm not an experienced dev. So can miss or don't understand something.
Some ideas?
I've found the root cause.
Actually, the issue occurs not after submitButton.Click(); but after another action which is not provided here, since the error message is a bit confusing.
The thing is we used EasyRepro framework in our solution and getting rid of it now since it's not been supported for more than a year now.
If we take a look at EasyRepro login logic, there is such a method:
private static void EnterPassword(IWebDriver driver, SecureString password)
{
var input =
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.LoginPassword]));
input.SendKeys(password.ToUnsecureString());
input.Submit();
}
And the error is caused by input.Submit(); line. I just copied it in my new method.
It seems like the method submits the whole form before the login has time to be written somewhere.
So, I simply changed that to this one:
private bool EnterPassword(string password)
{
var passwordInput = _driver.FindElement(By.CssSelector("input[type =
'password']"));
passwordInput.SendKeys(password);
var submitButton = _driver.WaitUntilClickable(By.CssSelector("input[type =
'submit'][value = 'Sign in']"),
_defaultWait);
submitButton.Click();
var staySignedInDialog = _driver.WaitUntilAvailable(By.XPath("//div[contains(text(), 'Stay signed
in?')]"), _defaultWait);
return staySignedInDialog != null;
}
Hope will be useful for someone in the future.
I have created a lightning web component that is wrapped in a lightning component.
I am using the lightning component in quick action on the Contact object.
On the LWC we are querying the user attached to the current contact.
The class looks like below:
public without sharing class GetUserRecordClass {
#AuraEnabled
public static String printDetails( String argContactId ){
returnString = getUserRecord( argContactId );
}
private static String getUserRecord( String argContactId ){
try{
User userOnContact = [SELECT Id FROM User Where ContactId = :argContactId LIMIT 1];//Getting error on this line in QA org
String userId = userOnContact.Id;
return userId;
}
catch( Exception exceptionObject ){
System.debug( 'Exception occurred=' + exceptionObject.getMessage() );
System.debug( 'Stack trace=' + exceptionObject.getStackTraceString() );
throw exceptionObject;
}
}
}
The query on User is working fine in my Dev org.
I have deployed the code on QA org now.
I login into QA with the required user and click on the Quick Action button on the Contact record.
But getting below error in LWC:
List has no rows for assignment to SObject
The class is without sharing.
When I run the query with my user in the Developer console, I am able to get the result.
I tried verifying Org wide setting in both org and found a difference.
In Dev Org(Snapshot from Chrome):
In QA Org(Snapshot from Firefox):
I am not able to see Site User Visibility check box in the QA org. I believe by checking that, I may be able to fetch record in the QA org Apex.
Can you please let me know where to look else for this?
This exception usually happens when a batch is being run or alerts are coming into our Salesforce instance too quickly. When inserting a case, we try to lock down the contact and account associated with the case before inserting the case to prevent the 'UNABLE_TO_LOCK_ROW' exception from happening.
Here is the exact exception:
'System.QueryException: Record Currently Unavailable: The record you are attempting to edit, or one of its related records, is currently being modified by another user. Please try again.'
Class.Utility.DoCaseInsertion: line 98, column 1
I've done a lot of research on the 'UNABLE_TO_LOCK_ROW' exception and 'Record Currently Unavailable' exception and I can't seem to find a great solution to this issue.
What I've tried to accomplish is a loop to attempt the insert 10 times, but I'm still getting the 'Record Currently Unavailable' exception. Does anyone else have a suggestion for this?
Below is the code:
Public static void DoCaseInsertion(case myCase) {
try
{
insert myCase;
}
catch (System.DmlException ex)
{
boolean repeat = true;
integer cnt = 0;
while (repeat && cnt < 10)
{
try
{
repeat = false;
List<Contact> contactList = [select id from Contact where id =: myCase.ContactId for update]; // Added for related contact to overcome the 'UNABLE_TO_LOCK_ROW issues'
List<Account> accountList = [select id from Account where id =: myCase.AccountId for update]; // Added for related account to overcome the 'UNABLE_TO_LOCK_ROW issues'
insert myCase;
}
catch (System.DmlException e)
{
repeat = true;
cnt++;
}
}
}
}
This basically happens when there is a conflicting modification being done by other user/process on a particular record that you are trying to access. Mostly it will happen when anykind of batch process is running in the background and locked the particular record you are trying to access(in your case Account). To get rid of this problem, you would need to check if there are any scheduled apex classes running in the background on Accounts/Cases and see if there is anything you can do to optimize the code to avoid conflicting behavior.
When user clicks the link this method takes the user id and other data and writes it to the database. I can't seem to find a way to track what is the user id since the id is automatically generated.
I am using membership base separately from my base. In order to find userID I was trying to compare UserName strings. I get this error: "An unhandled exception was generated during the execution of the current web request." Also "Cannot create an abstract class."
Is there a better way to compare two strings form the two databases? Or is there a better way? This is my first time using lambda expressions.
I tried using Single() and First() instead of Where(), but I still get the same error.
[HttpPost]
public ActionResult AddToList(Review review, int id, HttpContextBase context)
{
try
{
if (ModelState.IsValid)
{
//User user = new User();
//user.UserID = db.Users.Where(c => c.UserName == context.User.Identity.Name);
User user = new User();
Movie movie = db.Movies.Find(id);
review.MovieID = movie.MovieID;
string username = context.User.Identity.Name;
user = (User)db.Users.Where(p => p.UserName.Equals(username));
review.UserID = user.UserID;
db.Reviews.Add(review);
db.SaveChanges();
return RedirectToAction("Index");
};
}
catch (DataException)
{
//Log the error (add a variable name after DataException)
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
}
return View(review);
}
you're problem is likely this line:
user = (User)db.Users.Where(p => p.UserName.Equals(username));
the Where() extension method returns an IEnumerable, not a single instance, so your implicit cast will fail every time. what you're looking for is either First() or FirstOrDefault(). First() will throw an exception if there is no match though, while FirstOrDefault()will return a null if no match is found. the line should be :
user = db.Users.First(p => p.UserName.Equals(username));
you probably have bigger problems than that, but this is the cause of your current error.
EDIT
upon further looking at your code, you're asking for a HttpContextBase in your action result call. you never use it, and it's probably the cause of the Cannot create an abstract class exception. remove that parameter and see if you get any different results.
I have a Visual Studio solution with a Silverlight project, and a web project which hosts the Silverlight app. The web project also contains an ASMX web service which is called by the Silverlight ap.
As described below, certain calls to the web service work fine, and yet others cause a CommunicationException to be thrown, wrapping a WebException - both with the message "The server returned the following error: 'not found'".
Firstly, here's my original method, which failed as described above (entity names changed for simplicity):
[WebMethod]
public Customer GetCustomer(int id)
{
CustomerDataContext dc = new CustomerDataContext();
return dc.Customers.SingleOrDefault(x => x.Id == id);
}
Secondly, to debug the problem I took Linq to SQL and the database out of the picture, and the below code worked fine:
[WebMethod]
public Customer GetCustomer(int id)
{
Customer c = new Customer() { ID=1, Name="Bob", History = new EntitySet<CustomerHistory>() };
return c;
}
Third, thinking about this, one difference between the two methods is that the first one would include values in the customer history. I extended the second method to include this, and it started failing again:
[WebMethod]
public Customer GetCustomer(int id)
{
Customer c = new Customer() { ID=1, Name="Bob", History = new EntitySet<CustomerHistory>() };
c.History.Add(new CustomerHistory() { Id=1, CustomerId=1, Text="bla" });
return c;
}
I'm stuck with regards to how to progress - my current thinking is that this could be a deserialization issue on the Silverlight side, when the object graph is deeper. This rationally doesn't make sense, but I can't think of anything else. I've confirmed that the transfer size and buffer size are big enough (2GB by default).
Any pointers would be appreciated.
Ahhhh the famous "Not Found" error, try to get details from that error using the tag in your web.config. That will create a log file providing details of the error.
The following link explains exaclty how to do it :
http://blogs.runatserver.com/lppinson/post/2010/04/15/Debugging-WCF-Web-Services.aspx