You need to sign in to do that
Don't have an account?
Andrey Petuhov
how to check if record name already exists or not
Hi friends, I just learing SF. Help me: I how do i check if name record already exists or not in the database. If record already exists, then do nothing, if not exists insert the record.
And then refresh page if record inserting.
My code:
------------------------------------------------
public class CarGarageController {
public Car__c car { get; set; }
public String carName { get; set; }
public Car_Garage__c carGarage { get; set; }
public CarGarageController () {
getCars();
}
public void receiveCarName() {
String carName=Apexpages.currentPage().getParameters().get('carName');
}
public PageReference insertCar() {
carGarage = [
SELECT Id
FROM Car_Garage__c
LIMIT 1
];
car = new Car__c(Car_Garage__c=carGarage.id, Name=carName);
insert car;
return null;
}
public List<Car__c> carList { get; set; }
private void getCars() {
carList = [
SELECT Id, Name, Car_Garage__c, CreatedByID, CreatedDate
FROM Car__c
ORDER BY Name ASC
];
}
}
------------------------------------------------
Thanks for answers!
And then refresh page if record inserting.
My code:
------------------------------------------------
public class CarGarageController {
public Car__c car { get; set; }
public String carName { get; set; }
public Car_Garage__c carGarage { get; set; }
public CarGarageController () {
getCars();
}
public void receiveCarName() {
String carName=Apexpages.currentPage().getParameters().get('carName');
}
public PageReference insertCar() {
carGarage = [
SELECT Id
FROM Car_Garage__c
LIMIT 1
];
car = new Car__c(Car_Garage__c=carGarage.id, Name=carName);
insert car;
return null;
}
public List<Car__c> carList { get; set; }
private void getCars() {
carList = [
SELECT Id, Name, Car_Garage__c, CreatedByID, CreatedDate
FROM Car__c
ORDER BY Name ASC
];
}
}
------------------------------------------------
Thanks for answers!
Try The Below Trigger
Please Mark It As Best Answer If It Helps
THANK you!
All Answers
>> https://help.salesforce.com/articleView?id=sf.duplicate_rules_map_of_reference.htm&type=5
By default there is duplicate rules that detect the duplicates before inserting the record you can read regarding these in the above link.
>> https://developer.salesforce.com/forums/?id=906F0000000Apt8IAC
You can try the above link that has a custom implementation of check duplicates on case trigger you can modify it to your implementation:
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
Try The Below Trigger
Please Mark It As Best Answer If It Helps
THANK you!
Try The Below Trigger
If you find this helpful please mark it as a best answer.
Thanks And Regards ,
Suraj Tripathi.