You need to sign in to do that
Don't have an account?
I can not cover 100% class
Hello
Can you help me with this class, I can not cover 100%.
The strange thing is that this code is already in production, the only thing that was done was change the Object FACTURA__C appends a date field,
Below is the code and error mnesaje
I hope I can help
Greetings.
CODE
globalclass BatchLeadPhones implementsDatabase.Batchable<sObject>{
publicString query, query1;
globaldatabase.querylocator start(Database.BatchableContext BC){
query='Select Id, Name, Nombre_del_Cliente__c, Proceso__c, Fecha_de_Pago__c From Factura__c Where Proceso__c = "no validado"';
//query1='Select Id, StageName, Status_de_Oportunidad__c, Numero_de_la_Factura__c From Opportunity Where Numero_de_la_Factura__c="Cerrada Ganada"';returnDatabase.getQueryLocator(query);
//return Database.getQueryLocator(query1);
}
globalvoidexecute(Database.BatchableContext BC, List<sObject> scope){
List<Factura__c> Leads = new List<Factura__c>();
//List<Opportunity> st = new List<Opportunity>(); for(sObject s : scope){
Factura__c l = (Factura__c)s;
for(List<Opportunity> st : [SELECT Id, Numero_de_la_Factura__c, Status_de_Oportunidad__c, Status_Factura__c FROMOpportunityWHERE Numero_de_la_Factura__c =: l.Name]){
for(Opportunityopor:st){
if (opor.Numero_de_la_Factura__c == l.Name){
opor.Status_Factura__c ='Pagada';
l.Proceso__c ='Terminado';
opor.Fecha_confirmacion_de_Pago__c = l.Fecha_de_Pago__c;
}
}
updatest;
}
//Opportunity f = (Opportunity)ac;//If (ac.Numero_de_la_Factura__c==l.Name){//ac.Status_de_Oportunidad__c ='Pagada';//l.Nombre_del_Cliente__c = 'Validada';
Leads.Add(l);
//}
}
update
Leads;
//update f;
}
globalvoidfinish(Database.BatchableContext BC){
}
// test method
statictestMethodvoidtest_BatchLeadPhones() {
//Lead l = new lead(LastName='lead test 123', phone_cti__c='+1 (555)123-4567', company='test company 456'); //insert l;
Test.StartTest();
BatchLeadPhones Blp =
newBatchLeadPhones();
//Blp.query = 'Select phone_cti__c From lead Where ID=\''+l.Id+'\'';
ID batchprocessid = Database.executeBatch(Blp);
Test.StopTest();
}
}
Debug Log:
18.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO
14:51:47.776 (776858000)|EXECUTION_STARTED
14:51:47.776 (776922000)|CODE_UNIT_STARTED|[EXTERNAL]|01pA00000034QEg|BatchLeadPhones.test_BatchLeadPhones
14:51:47.776 (776986000)|METHOD_ENTRY|[1]|01pA00000034QEg|BatchLeadPhones.BatchLeadPhones()
14:51:47.777 (777029000)|METHOD_EXIT|[1]|BatchLeadPhones
14:51:47.777 (777078000)|SYSTEM_METHOD_ENTRY|[1]|Test.Test()
14:51:47.777 (777108000)|SYSTEM_METHOD_EXIT|[1]|Test
14:51:47.777 (777250000)|CONSTRUCTOR_ENTRY|[43]|01pA00000034QEg|<init>()
14:51:47.777 (777321000)|CONSTRUCTOR_EXIT|[43]|01pA00000034QEg|<init>()
14:51:47.816 (816347000)|CODE_UNIT_STARTED|[EXTERNAL]|01pA00000034QEg|BatchLeadPhones
14:51:47.829 (829443000)|SYSTEM_METHOD_ENTRY|[15]|BatchableContextImpl.BatchableContextImpl()
14:51:47.829 (829485000)|SYSTEM_METHOD_EXIT|[15]|BatchableContextImpl
14:51:47.830 (830040000)|EXCEPTION_THROWN|[6]|System.QueryException: line 1:104 no viable alternative at character '"'
14:51:47.850 (850630000)|FATAL_ERROR|System.QueryException: line 1:104 no viable alternative at character '"'
Class.BatchLeadPhones.start: line 6, column 13
External entry point
14:51:47.977 (850656000)|CUMULATIVE_LIMIT_USAGE
14:51:47.977|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 0 out of 200
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Number of script statements: 2 out of 1000000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 1
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 0
14:51:47.977 (850656000)|CUMULATIVE_LIMIT_USAGE_END
14:51:47.850 (850701000)|CODE_UNIT_FINISHED|BatchLeadPhones
14:51:47.977 (850758000)|CUMULATIVE_LIMIT_USAGE
14:51:47.977|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Number of script statements: 6 out of 200000
Maximum heap size: 0 out of 3000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10
14:51:47.977|TESTING_LIMITS
14:51:47.977 (850758000)|CUMULATIVE_LIMIT_USAGE_END
14:51:47.850 (850789000)|CODE_UNIT_FINISHED|BatchLeadPhones.test_BatchLeadPhones
14:51:47.850 (850795000)|EXECUTION_FINISHED
remove the single quotes in Soql queries and also give LIMIT 1 in the SOQL uery.U will get through
You should write query in this way...Salesforce doesn't support double quotes.
query='Select Id, Name, Nombre_del_Cliente__c, Proceso__c, Fecha_de_Pago__c From Factura__c Where Proceso__c = 'no validado';
Make changes in your query and run the test.