I am getting this error
unexpected token: 'where' at line 13 column 281
public with sharing class Form_Salgsplakat_Bilpris {
dealer__Vehicle_Inventory__c vi =new dealer__Vehicle_Inventory__c();
public dealer__Vehicle_Inventory__c getvi()
{
return vi;
}
public Form_Salgsplakat_Bilpris(ApexPages.StandardController controller)
{
// Deal id
// Slect vehicleID from RelatedLook wher deal = "pagId" limit 1;
vi=[Select id,Name,Brand__c,Description_salesprospect__c,dealer__Exterior_Color__c,dealer__Interior_Color__c,dealer__Stock_Number__c,Engine_Displacement_CC__c,Horsepower__c,dealer__Max_Torque__c,Dry_weight_kg__c,Extra_urban__c,CO2_emissions_g_km__c,dealer__Mileage__c from where id IN:[select id,Name,dealer__Vehicle__c from dealer__Deal__c where dealer__Vehicle__c IN:controller.getRecord().id]LIMIT 1];
}
}
Your query needs to include the object to query, you have
ler__Mileage__c from where id IN:[select id,N
needs to be
ler__Mileage__c from <InsertSObjectName> where id IN:[select id,N
Related
could anyone help me with how to manage this problem? I am trying to code exactly likes the course's video, but I got this problem:
I'm getting (Non-nullable instance field 'id' must be initialized.
Non-nullable instance field 'miles' must be initialized.
Non-nullable instance field 'name' must be initialized. Non-nullable instance field '_database' must be initialized.)
. errors in my project.
My car class:
import './dbhelper.dart';
class Car {
int id;
String name;
int miles;
Car(this.id, this.name, this.miles);
**GET ERROR FROM Car.fromMap..**
Car.fromMap(Map<String, dynamic> map) {
** Non-nullable instance field 'id' must be initialized.
Non-nullable instance field 'miles' must be initialized.
Non-nullable instance field 'name' must be initialized.**
id = map['id'];
name = map['name'];
miles = map['miles'];
}
Map<String, dynamic> toMap() {
return {
DatabaseHelper.columnId: id,
DatabaseHelper.columnName: name,
DatabaseHelper.columnMiles: miles,
};
}
}
My dbHelper.dart:
import './car.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
class DatabaseHelper {
static final _databaseName = "cardb.db";
static final _databaseVersion = 1;
static final table = 'cars_table';
static final columnId = 'id';
static final columnName = 'name';
static final columnMiles = 'miles';
** GET ERROR FROM DatabaseHelper._provateConstructor(); AND _database;
Non-nullable instance field '_database' must be initialized.**
DatabaseHelper._privateConstructor();
static final DatabaseHelper instance = DatabaseHelper._privateConstructor();
** GET ERROR Non-nullable instance field '_database' must be initialized.**
static Database _database;
Future<Database> get database async {
if (_database != null) return _database;
// lazily instantiate the db the first time it is accessed
_database = await _initDatabase();
return _database;
}
// this opens the database (and creates it if it doesn't exist)
_initDatabase() async {
String path = join(await getDatabasesPath(), _databaseName);
return await openDatabase(path,
version: _databaseVersion,
onCreate: _onCreate);
}
// SQL code to create the database table
Future _onCreate(Database db, int version) async {
await db.execute('''
CREATE TABLE $table (
$columnId INTEGER PRIMARY KEY AUTOINCREMENT,
$columnName TEXT NOT NULL,
$columnMiles INTEGER NOT NULL
)
''');
}
// Helper methods
// Inserts a row in the database where each key in the Map is a column name
// and the value is the column value. The return value is the id of the
// inserted row.
Future<int> insert(Car car) async {
Database db = await instance.database;
return await db.insert(table, {'name': car.name, 'miles': car.miles});
}
// All of the rows are returned as a list of maps, where each map is
// a key-value list of columns.
Future<List<Map<String, dynamic>>> queryAllRows() async {
Database db = await instance.database;
return await db.query(table);
}
// Queries rows based on the argument received
Future<List<Map<String, dynamic>>> queryRows(name) async {
Database db = await instance.database;
return await db.query(table, where: "$columnName LIKE '%$name%'");
}
// All of the methods (insert, query, update, delete) can also be done using
// raw SQL commands. This method uses a raw query to give the row count.
Future<int> queryRowCount() async {
Database db = await instance.database;
return Sqflite.firstIntValue(await db.rawQuery('SELECT COUNT(*) FROM $table'));
}
// We are assuming here that the id column in the map is set. The other
// column values will be used to update the row.
Future<int> update(Car car) async {
Database db = await instance.database;
int id = car.toMap()['id'];
return await db.update(table, car.toMap(), where: '$columnId = ?', whereArgs: [id]);
}
// Deletes the row specified by the id. The number of affected rows is
// returned. This should be 1 as long as the row exists.
Future<int> delete(int id) async {
Database db = await instance.database;
return await db.delete(table, where: '$columnId = ?', whereArgs: [id]);
}
}
You have to put the null aware operator in the variables type for example:
class Car {
int? id; // <---- add a ? to int so it will be int?
String? name; // <-- same here
int? miles; // <--- and here
Car({this.id, this.name, this.miles});
Car.fromMap(Map<String, dynamic> map) {
id = map['id'];
name = map['name'];
miles = map['miles'];
}
Map<String, dynamic> toMap() {
return {
DatabaseHelper.columnId: id,
DatabaseHelper.columnName: name,
DatabaseHelper.columnMiles: miles,
};
}
}
Null safety as it is explain in the dart documentation:
When you opt into null safety, types in your code are non-nullable by
default, meaning that variables can’t contain null unless you say they
can. With null safety, your runtime null-dereference errors turn into
edit-time analysis errors.
More information in: https://dart.dev/null-safety
Maybe the tutorial you are taking was previous the null aware implementation and it does not apply the null aware operators, you can do the same at the beggining of the type declartion where the error is happening in other classes, you just have to add ? to the variable type at the beginning of the variable.
I am trying to implement a simple change for an apex class in production. I have the proper class and proper test class. The test class runs successfully in sandbox without errors, but apparently the error is coming from the TestHelper default test class in Salesforce. When trying to deploy in production it throws the error "Method does not exist or incorrect signature: void createUser(Id, String, String, Date, Integer) from the type TestHelper"
I've tried the usual of changing the method it references to public static void, but to no avail, it throws errors in code
This is my test class:
#isTest
private class OppLineItemInvntryBO_AType_OppStge_Test {
#testSetup public static void setup() {
Profile p = [SELECT Id FROM Profile
WHERE Name = 'profile1' LIMIT 1];
Date myDate = Date.newinstance(2019,07,01);
User testUser = TestHelper.createUser(p.Id,
'company1','legalentity1',myDate,327001);
And this is my TestHelper class:
public with sharing class TestHelper {
public static User createUser(Id profileId, String company) {
Integer rnd = getRandomNumber(10000);
User user = new User(
Username = 'john.doe#acme.com' + String.valueOf(rnd),
Email = 'john.doe' + String.valueOf(rnd) + '#acme.com',
LastName = 'Doe',
FirstName = 'John',
Alias = 'JD' + String.valueOf(rnd),
ProfileId = profileId,
LocaleSidKey = 'en_US',
LanguageLocaleKey = 'en_US',
TimeZoneSidKey = 'America/Los_Angeles',
EmailEncodingKey='UTF-8',
CompanyName = company);
insert user;
return user;
}
public static Integer getRandomNumber(Integer size){
Double d = math.random() * size;
return d.intValue();
}
}
The full error is this:
API Name - OppLineItemInvntryBO_AType_OppStge_Test
Type - Apex Class
Line - 14
Column - 36
Error Message - Method does not exist or incorrect signature: void createUser(Id, String, String, Date, Integer) from the type TestHelper
You are invoking the createUser method with 5 parameters in OppLineItemInvntryBO_AType_OppStge_Test class where as in the TestHelper class , the createUser method accepts only 2 parameters. Thats why you are getting this error. Try to invoke the method with correct parameters.
I have an 'Edit page' with a form, where I want to update some data.
My Models:
Actividad.php:
public function materials()
{
return $this->belongsToMany('Material', 'actividad_material')->withTimestamps();
}
And Material.php:
public function actividads()
{
return $this->belongsToMany('Actividad', 'actividad_material')->withTimestamps();
}
My code (Controller):
public function update($id)
{
$input = array_except(Input::all(), '_method');
$v = Validator::make($input, Actividad::$rules);
// return 'Hala';
if($v->passes())
{
$actividad = Actividad::find($id);
$material_id = Input::get('material_id');
$actividad->materials()->sync($material_id);
Actividad::find($id)->update($input);
// return 'hola';
return Redirect::route('actividads.index');
}
return Redirect::back()->withErrors($v);
}
The application gives me an error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'material_id' in 'field list' (SQL: update actividads set updated_at = 2014-07-20 16:20:03, material_id = 1 where id = 16)
I suppose it is because it's looking for a column in my 'actividads' that doesn't already exist! Maybe I have to change $input = array_except(Input::all(), '_method');... I think I'm telling with that, that every inputs in the form are in my 'Actividad', and this is not true. I need to update my pivot table with 'material_id'.
Thank you very much in advance!
So I have followed this example to an absolute tee: http://www.startutorial.com/articles/view/build-a-shopping-cart-with-cakephp-and-jquery-part-2
But yet it gives me an error:
Warning (2): Invalid argument supplied for foreach() [APP\Model\Cart.php, line 38]
Which relates to:
public function getCount() {
$allProducts = $this->read();
if (count($allProducts)<1) {
return 0;
}
$count = 0;
foreach ($allProducts as $product) {
debug($product);
$count=$count+$product;
}
return $count;
}
What makes it even more infuriating is that in the first place it was working properly. Then something happened, I do not know what. It now refuses to work. My database is correct, everything is correct.
I just don't understand I have been stuck on this for so hours upon hours
And also, it must be related, whenever I try to access my shopping car(CartsController)t it gives me:
Error: syntax error, unexpected 'class' (T_CLASS)
Here is a picture of everything, that line of errors abovwe is when i click on add to cart. And when I click on shopping cart, it gets me the snytax error about unexpected class
Cart.php
<?php
App::uses('AppModel', 'Model');
App::uses('CakeSession', 'Model/Datasource');
class Cart extends AppModel {
public $useTable = false;
/*
* add a product to cart
*/
public function add($productId) {
$allProducts = $this->read();
if (null!=$allProducts) {
if (array_key_exists($productId, $allProducts)) {
$allProducts[$productId]++;
} else {
$allProducts[$productId] = 1;
}
} else {
$allProducts[$productId] = 1;
}
$this->save($allProducts);
}
/*
* get total count of products
*/
public function getCount() {
$allProducts = $this->find('all');
if (count($allProducts)<1) {
return 0;
}
$count = 0;
foreach ($allProducts as $product) {
$count=$count+$product;
}
return $count;
}
/*
* save data to session
*/
public function save($data) {
return CakeSession::write('cart',$data);
}
/*
* read cart data from session
*/
public function read() {
return CakeSession::read('cart');
}
}
You seem to be mixing up model methods. The read() method is meant to read a single row from your data model (usually a database table) as it requires an id, either by setting it to the model:
$this->id = 2;
$this->read();
Or by setting it as second argument:
$this->read(null, 2);
But, by the look of it, you're trying to fetch a count of all your products, which can be obtained much simpler with the find('count') method. Your model method can be as skinny as this:
public function getCount() {
return $this->find('count');
}
Should give you the desired results.
I am fairly new to EasyMock. I am trying to write a EasyMock test for my Spring WS Endpoint and keep running to a issue. Details are listed below:
Endpoint:
#PayloadRoot(namespace = NAMESPACE_URI, localPart = "UserCreate")<BR>
public void handleUserCreationRequest(#RequestPayload Element userCreate) throws JDOMException {
String userName = userNameExp.valueOf(userCreate);
String loginName = userLoginNameExp.valueOf(userCreate);
String eMail = eMailExp.valueOf(userCreate);
String region = regionExp.valueOf(userCreate);
String department = departmentExp.valueOf(userCreate);
String businessUnit = businessUnitExp.valueOf(userCreate);
userManagementService.userCreate(userName, loginName, eMail,
region, department, businessUnit);
}
Test:
#Before<BR>
public void setUp() throws JDOMException {<BR>
xPath = createNiceMock(XPath.class);<BR>
payload = createNiceMock(Element.class);<BR>
managementService = createStrictMock(UserManagementService.class);<BR>
serviceEndpoint = new UserManagementServiceEndpoint(managementService);
}
#Test
public void testUserCreationHandler() throws JDOMException {
expect(xPath.valueOf(payload)).andReturn("userName");
expect(xPath.valueOf(payload)).andReturn("loginName");
expect(xPath.valueOf(payload)).andReturn("eMail");
expect(xPath.valueOf(payload)).andReturn("region");
expect(xPath.valueOf(payload)).andReturn("department");
expect(xPath.valueOf(payload)).andReturn("businessUnit");
managementService.userCreate("userName", "loginName", "eMail",
"region", "department", "businessUnit");
expectLastCall();
replayAll();
serviceEndpoint.handleUserCreationRequest(payload);
verifyAll();
}
Error Message:
Failed tests:
testUserCreationHandler(com.xxx.usermanagement.endpoint.UserManagementServiceEndpoint
Test):
Expectation failure on verify:
valueOf(EasyMock for class org.jdom.Element): expected: 6, actual: 0
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0<BR><BR>
I would appreciate if anyone can help me on this. Thanks in advance.
The problem you have here is that your XPath mock object is not set to your UserManagementServiceEndpoint object.
You should either modify the constructor to accept an XPath parameter or create a setter for it.