You need to sign in to do that
Don't have an account?
Samadhan Sakhale 3
Batchable Class Query
How to Copy Custom Object Field record (i.e.phone) to Standard Object field.
Reply me.
Reply me.
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
If you need to have it as text then you have to creae a
Set<String> setSturdentIds = new Set<String>();
and loop over scope and fill it. Then use it this query
List<Address1__c> adrToUpdate = [Select id,StudentID__c,City__c from Address1__c where StudentID__c in : setSturdentIds ]
Let me know if it does not solve your problem.
All Answers
actually ihave to copy all the records of field city from student object to address1 object in field city so by using batch job
all records copied at a time and placed in front of related data only and that may use ID's to find actual record
here is code by using i am trying to copy
lobal class CopyStudtoAdr_Batch implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
String query='SELECT ID,City__c FROM Student__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Student__c> scope)
{
List<Address1__c> adrToUpdate = [Select id,StudentID__c,City__c from Address1__c where StudentID__c in : scope] ;
Map<ID,Student__c> stdMap = new Map<ID,Student__c>(scope) ;
// Loop to copy account Phone to contact phone
for(Address__c adr : adrToUpdate)
adr.City__c = stdMap.get(adr.StudentID__c).City__c ;
if(adrToUpdate.size() > 0)
update adrToUpdate;
}
global void finish(Database.BatchableContext ctx)
{}
}
But in this code it gives error 'Invalid bind expression type of SOBJECT:Student__c for column of type String'
so please help me for solve example
Thank you,
Regards,
Sam
If you need to have it as text then you have to creae a
Set<String> setSturdentIds = new Set<String>();
and loop over scope and fill it. Then use it this query
List<Address1__c> adrToUpdate = [Select id,StudentID__c,City__c from Address1__c where StudentID__c in : setSturdentIds ]
Let me know if it does not solve your problem.
As you suggested i follow each and every procedure but when i run my test class that time it gives only 11% coverage i didnt understand the problem
so please help me.My code is here,
global class CopyStudtoAdr_Batch implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
String query='SELECT ID,City__c FROM Student__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Student__c> scope)
{
//List<Address1__c> adrToUpdate = [Select id,StudentID__c,City__c from Address1__c where StudentID__c in : scope] ;
Set<String> setSturdentIds = new Set<String>();
List<Address1__c> adrToUpdate = [Select id,StudentID__c,City__c from Address1__c where StudentID__c in : setSturdentIds];
Map<ID,Student__c> stdMap = new Map<ID,Student__c>(scope) ;
// Loop to copy account Phone to contact phone
for(Address1__c adr : adrToUpdate)
adr.City__c = stdMap.get(adr.StudentID__c).City__c ;
if(adrToUpdate.size() > 0)
update adrToUpdate;
}
global void finish(Database.BatchableContext ctx)
{}
}
and test class is,
@isTest(seeAllData = true)
public class TestStudent
{
static testMethod void Test_Copystudtoadr()
{
String query = 'select ID,City__c from Student__c';
List<Student__c> stdList = new List<Student__c>();
for (Integer i=0;i<200;i++)
{
Student__c std = new Student__c(Name='Test Student' + i);
stdList.add(std);
}
insert stdList;
System.Test.startTest();
System.debug('Test Started....');
CopyStudtoAdr_Batch csta = new CopyStudtoAdr_Batch();
Database.executeBatch(csta, 200);
System.Test.stopTest();
System.debug('Test stopped');
}
}
Thanks.