I am new to Salesforce Development, I have tested a similar query to this in a sandbox Org which worked, however when trying to update records in the live Org I am having some issues.
The issue and context is as follows:
I am trying to update the 'Record Type' field of certain Job records through Apex DML. I have opened the Developer Console and run a query:
SELECT Name, GW_Volunteers__Campaign__c, RecordtypeId FROM GW_Volunteers__Volunteer_Job__c WHERE GW_Volunteers__Campaign__c = '7010O000001P2XIQA0' and RecordTypeId = null LIMIT 5
This works fine and will show me the first 5 job records where there is no assigned record type, which is what I want to update.
The problem is when I am opening "execute anonymous" window and entering this code:
GW_Volunteers__Volunteer_Job__c [] bjobs = [
SELECT Name, GW_Volunteers__Campaign__c, RecordTypeId FROM GW_Volunteers__Volunteer_Job__c WHERE GW_Volunteers__Campaign__c = '7010O000001P2XIQA0' and RecordTypeId = null LIMIT 5];
bjobs.RecordTypeId='0120O000000LAY6QAO';
update bjobs;
I keep getting the following error:
Line: 3, Column: 11 Variable does not exist: RecordTypeId
Unless I have missed something very obvious, I cannot figure out why this is happening. Since it recognizes that variable in the query fine and a similar query (where I also updated the RecordTypeId) in the sandbox worked.
Thank you,
YH
The problem here is, you cannot assign bjobs.RecordTypeId='0120O000000LAY6QAO';. You know, bjobs is an array of GW_Volunteers__Volunteer_Job__c.
So, what you need to do is,
GW_Volunteers__Volunteer_Job__c [] bjobs = [
SELECT Name, GW_Volunteers__Campaign__c, RecordTypeId FROM GW_Volunteers__Volunteer_Job__c WHERE GW_Volunteers__Campaign__c = '7010O000001P2XIQA0' and RecordTypeId = null LIMIT 5];
for(GW_Volunteers__Volunteer_Job__c job : bjobs)
{
job.RecordTypeId='0120O000000LAY6QAO';
}
update bjobs;
Hope, this will work.
Related
I have a select statement That I need to turn into an Update.
I need to update a particular unix time field to January 1, 2016.
I have to select the records using a compound select statement.
Update archive_queue set archive_time = 1451606400
FROM
select recordings.(star), archive_queue.(star)
from
recordings, archive_queue
where
recordings.device_alias = '70285' and recordings.keepdays = 120
and recordings.ident = archive_queue.rec_ident
The above gives me a syntax error. The select gives me the records that I need to update. I looked at some examples here, but can't figure out the proper syntax based on my needs. Thanks everyone !
You should remove the select and only have one FROM statement:
Update archive_queue set archive_time = 1451606400
from recordings, archive_queue
where recordings.device_alias = '70285' and recordings.keepdays = 120
and recordings.ident = archive_queue.rec_ident
I have the following update query running nightly which updates GIS information in a SQL spatial database (GIS) to another database (LIVE). This update has worked without issue for a few months and all of a sudden today it fails with
"Error converting data type from varchar to numeric."
update LIVE.dbo.PT001
Set
LIVE.dbo.pt001.dlonglegal_1 = Left(GIS.dbo.parcel.quartersection,2),
LIVE.dbo.pt001.dlonglegal_2 = SUBSTRING(GIS.dbo.parcel.quartersection,3,CHARINDEX('-',GIS.dbo.parcel.quartersection+'-')-3),
LIVE.dbo.pt001.dlonglegal_3 = SUBSTRING(GIS.dbo.parcel.quartersection,CHARINDEX('-',GIS.dbo.parcel.quartersection+'-')+1,1),
LIVE.dbo.pt001.dlonglegal_4 = SUBSTRING(GIS.dbo.parcel.quartersection,CHARINDEX('-',GIS.dbo.parcel.quartersection+'-')+3,1),
LIVE.dbo.pt001.dlonglegal_5 = right(GIS.dbo.parcel.quartersection,1)
From GIS.dbo.parcel inner Join
LIVE.dbo.PT001 on GIS.dbo.parcel.roll = LIVE.dbo.pt001.dROLLNMBR
where GIS.dbo.parcel.roll = LIVE.dbo.PT001.drollnmbr AND
GIS.dbo.parcel.quartersection is not null
The quartersection information is stored in the parcel table as nvarchar(30) with the following format:
NW12-5-6E
In the destination table it would be stored as char(15) and as follows:
dlonglegal_1 = NW
dlonglegal_2 = 12
dlonglegal_3 = 5
dlonglegal_4 = 6
dlonglegal_5 = E
I've tried casting the numeric fields as numeric without success. I'm stumped as why the update started failing today as there have been no changes to the database structure in a long time.
Like artm suggested I thought the most likely scenario was an issue with the data but everything was correct. I ran the update for each column separately and it worked for each one. I then ran the full query and it completed without issue. I'm not sure what the final problem was but evidently it appears to be working again. I thank you for your input.
I am trying to make a report, where I can select a multiple values from a parameter - and then make a query, where i state "where in (#partner)"
However, my problems occours, when I want to make a value, that will not do the "where in (#partner)", but will simply select all from the same query, without the where in clause - as not all rows in my db table, have the specific values set, so I want to catch them too.
All the values for the parameter is selected from a query, and I have a union on it, to create a value for the one, where I need to select all - not using the where in.
It actually works, if only one value from the parameter list is chosen - but as soon as I try to select 2 or more, I get the error "query execution failed for dataset1......"
The value of the parameter value, that is used for selecting all is 0, as you see in the code - and it does work as I can execute both select statements below, but not when I select more then 1 value from the parameter list.
IF #partner = 0
BEGIN
SELECT
thedata
FROM
thetable
WHERE
thedata = 3
END
ELSE
SELECT
thedata
FROM
thetable
WHERE
thedata = 3
and partner in (#partner)
END
ELSE
Hope there is some clever guys out there:) Thanks
Just do:
SELECT thedata
FROM thetable
WHERE thedata = 3
AND (partner IN (#partner) or #partner = 0)
I can limit the size of characters of table field in mysql as simple
SELECT NID,LEFT(BODY, 10) AS text FROM tablename
but how can i get the same result in codeigniter Active Record
I tried this code
$this->db->select('NID, LEFT(BODY,10)');
$query = $this->db->get_where('tablename');
but not working
is it possible to make that in codeigniter Active Record ??
I've been able make it work in Codeigniter using a syntax like this:
$this->db->select('NID, LEFT(BODY,10) BODY', false);
$query = $this->db->get_where('tablename');
as stated in: http://ellislab.com/forums/viewthread/201014/#940615
adding 'false' to select, avoids the automatic backtics
also, after left(BODY, 10), you must add the name the new chopped field will use:
select('NID, LEFT(BODY,10) BODY'
otherwise, Codeigniter will output an Undefined property error.
I hope it works!
I'm having some trouble trying to set a 'WHERE field IN ...' clause in CodeIgniter using SQLite. I got an array of all where clause conditions called $conditions, and added the WHERE IN clause in this way:
$this->browse_model->conditions['username IN'] = "(SELECT like_to FROM likes WHERE like_from = '".$this->user->username."')";
and inside of my browse_model I use the following code to run the query:
$get = $this->db->get_where('users', $this->conditions, 6, $_SESSION['browse_page']*6);
but somehow when I use the condition I wrote above it is giving me the following error:
Fatal error: Call to a member function execute() on a non-object in
../www/system/database/drivers/pdo/pdo_driver.php on line 193
As far as I'm concerned the 'field IN array' statement is allowed in SQLite too, so I really don't know why this isn't working. Does anyone know how to make this work?
Thanks in advance!
Greets,
Skyfe.
EDIT: Tried setting the condition in the following way and didn't get an error but neither any results:
$this->browse_model->conditions['username'] = "IN (SELECT like_to FROM likes WHERE like_from = '".$this->user->username."')";
So I guess that's still not the correct way to do it..
EDIT2: 'Fixed' it, somehow it didn't interpetate the field => value way of notating the where clause correctly for the IN statement, so defined it in a custom string:
$this->browse_model->custom_condition = username IN (SELECT like_to FROM likes WHERE like_from = '".$this->user->username."')
Their is some problem in formatting IN clause,
SELECT * FROM users WHERE gender = 'f' AND gender_preference = 'm' AND username IN (SELECT like_to FROM likes WHERE like_from = 'testtest')