-
ChatterFeed
-
3Best Answers
-
0Likes Received
-
0Likes Given
-
18Questions
-
15Replies
Objects exposed in Customer Portal
Hi,
Could anyone please let me know if standard objects like Account, Product, Contract exposed in Customer Portal?
Also, which all objects can be exposed in Customer Portal?
Thanks,
Vimal
-
- champ_vimal
- December 29, 2010
- Like
- 0
- Continue reading or reply
System.Async Exception : Test failures when I run all tests
Hi,
I have created some batch apex code alongwith other triggers and class/controller codes.
When I run individual test methods on them, I am able to get test success result alongwith nice code coverage %. However when I run all tests together, I get following test failure errors:-
1)System.AsyncException: Database.executeBatch cannot be called from a batch or future method.
2)System.AsyncException: Future method cannot be called from a future method: changeOwners(String, String)
3)System.AsyncException: Future method cannot be called from a future method: getLead_Rollup_Amount(Id)
4)System.AsyncException: Future method cannot be called from a future method: changeOwners(String, String)
Please note again that the exceptions dont come when tested individually.
Please advise on same.
Thanks,
Vimal
-
- champ_vimal
- December 10, 2009
- Like
- 0
- Continue reading or reply
Want to make InputField field with value OwnerId not required
Hi,
I am having a field called 'Key User' in VisualForce which takes value of OwnerId thus making it required field in VF page.
But sometimes, it may happen that Key User needs to be null. But when I try to do it, I get this error on save.
System.DmlException: Update failed. First exception on row 0 with id a0GT0000000dImEMAU; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]
This is part of that VF page in which I am having the Key User field:-
<apex:pageBlockSectionItem id="keyUserId">
<apex:outputLabel value="Key User" id="labelUser"/>
<apex:inputField value="{!tr.OwnerId}" id="inputUserId" required="false"/>
</apex:pageBlockSectionItem>
Please advise.
Thanks,
Vimal
-
- champ_vimal
- December 02, 2009
- Like
- 0
- Continue reading or reply
Parts of ZipCode field values to be updated/removed and reflected
Hi,
I have a ZipCode field on a VisualForce page whose requirement is that even if part of zipcode is removed/updated/added, we have to send email to say record owner saying what was removed/updated/added. But please mind that whole of zipcode does not need to be sent as it may be long. Only the updated part needs to be sent as email message.
Examples:
1) If I have ZipCode initial value as : 11,22,33,44 and now I change to 11,22,33 mail should be that 44 is removed from ZipCode.
2) If I have ZipCode as : 11,22,33,44 and now I change to 11,22,33,55 mail should be that 44 is removed and 55 added to Zipcode.
3) If I have ZipCode as : 11,22,33,44 and now I change to 11,22,55,66 mail should be that 33 and 44 are removed and 55 and 66 are added to Zipcode.
Can I achieve this functionality without much pains if possible?
Thanks,
Vimal
-
- champ_vimal
- November 24, 2009
- Like
- 0
- Continue reading or reply
Lookup field in VisualForce page
Hi,
I have a visualforce page which has a UserRole field which needs to be lookup.
However, I am using custom controller for same. Can you please let me know how can I display lookup field for same in my visualforce page?
Thanks,
Vimal
-
- champ_vimal
- November 12, 2009
- Like
- 0
- Continue reading or reply
Dml operations on User Territory
Hi,
I know as per documentation that we cannot have Dml operations on User Territory records in Apex.
But, I think using @future call we can have a method in a single class and have the operation done. But for me it is 2 controller classes for one page module so this too wont work.
Please let me know how can I have delete operations on User Territory object records?
Thanks,
Vimal
-
- champ_vimal
- November 12, 2009
- Like
- 0
- Continue reading or reply
Zipcode field bounds
Hi,
I have a field 'Zipcode' to be displayed as plain text (outputtext) on a visualforce page.
However, whenever user enters many values the zipcode field gets long and it stretches the visualforce page. Can I have some way to wrap up the Zipcode field and display values on different lines?
Thanks,
Vimal
-
- champ_vimal
- November 06, 2009
- Like
- 0
- Continue reading or reply
Multiple Batch Processes via Batch Apex
-
- champ_vimal
- October 23, 2009
- Like
- 0
- Continue reading or reply
Batch Apex Issue
Hi,
I have created a batch apex class which assigns leads , opps, accounts to appropriate territories as per territory rules and other business logic.
I am clicking on custom button 'Run Rules' in Territory List View and calling the batch apex class and related method using javascript behaviour.
Right now, I am just testing for Leads(there are nearly 25K leads). 118 batches run properly while 1 batch fails. The error that it gives as per Debug log is:-
20091021124930.554:External entry point: returning NULL from method global Database.QueryLocator start(Database.BatchableContext) in 0 ms
This is my snapshot of Apex Jobs processing:-
Action | Submitted Date![]() | Job Type | Status | Total Batches | Batches Processed | Failures | Submitted By | Completion Date | Apex Class | Apex Method |
---|---|---|---|---|---|---|---|---|---|---|
10/21/2009 7:49 AM | Batch Apex | Failed | 0 | 1 | 1 | Desai, Vimal | 10/21/2009 7:49 AM | BatchApexTerritoryAssignmentBulk | ||
10/21/2009 7:49 AM | Batch Apex | Completed | 118 | 118 | 0 | Desai, Vimal | 10/21/2009 7:53 AM | BatchApexTerritoryAssignmentBulk |
The batch apex code is:-
global class BatchApexTerritoryAssignmentBulk implements Database.Batchable<SObject>
{
public String query;
global database.Querylocator start(Database.batchableContext bc)
{
Integer cont;
if(query == null)
cont = 1;
else
cont = 0;
if(cont == 0)
return Database.getQueryLocator(query);
else
return null;
}
global void execute(Database.BatchableContext BC, List<SObject> sobjList)
{
System.Debug('DATABASE.BATACHABLE CONTEXT' + BC);
System.Debug('SOBJECT LIST SIZE PASSED AS QUERY : ' + sobjList.size());
TerritoryAssignmentBulk tabObj = new TerritoryAssignmentBulk();
List<Lead> leadList = new List<Lead>();
Map<Id,Account> accMap = new Map<Id,Account>();
List<Opportunity> oppList = new List<Opportunity>();
for(sobject s : sobjList)
{
if(s.getsObjectType() == Lead.sObjectType)
{
Lead l = (Lead)s;
if(!l.isConverted)
{
leadList.add(l);
}
}
}
System.Debug('LEAD LIST SIZE : ' + leadList.size());
if(leadList.size()!=0)
{
tabObj.runRules(oppList, accMap, leadList, false);//The method that needs to be called, for lead all others will be null and boolean false
update leadList;
}
/*for(sobject s : sobjList)
{
if(s.getsObjectType() == Account.sObjectType)
{
Account a = (Account)s;
accMap.put(a.id,a);
}
}
if(accMap.size()!=0)
{
tabObj.runRules(oppList, accMap, leadList, false);//The method that needs to be called, for lead all others will be null and boolean false
update accMap.values();
} */
}
global void finish(Database.BatchableContext BC)
{
}
webservice static String BatchApexMethod(String objectType)
{
BatchApexTerritoryAssignmentBulk leadBulk = new BatchApexTerritoryAssignmentBulk();
BatchApexTerritoryAssignmentBulk accBulk = new BatchApexTerritoryAssignmentBulk();
if(objectType == 'Lead')
leadBulk.query = 'Select Id, Name, Company, Keep_in_Territory__c, LastName, Status, isConverted From Lead where isConverted = false';
System.Debug('QUERY' + leadBulk.query);
Id leadProcessId = Database.executeBatch(leadBulk);
/*if(objectType == 'Account')
accBulk.query = 'Select Id, Name From Account';
Id accountProcessId = Database.executeBatch(accBulk); */
return '';
}
}
The custom button code is :-
{!requireScript("/js/functions.js")}
{!requireScript("/soap/ajax/13.0/connection.js")}
{!requireScript("/soap/ajax/13.0/apex.js")}
try
{
var acc = "Account";
var lead = "Lead";
var opty = "Opportunity";
sforce.apex.execute("BatchApexTerritoryAssignmentBulk", "BatchApexMethod", {a:acc});
sforce.apex.execute("BatchApexTerritoryAssignmentBulk", "BatchApexMethod", {a: lead});
sforce.apex.execute("BatchApexTerritoryAssignmentBulk", "BatchApexMethod", {a: opty});
}
catch(e)
{
alert(e);
}
-
- champ_vimal
- October 21, 2009
- Like
- 0
- Continue reading or reply
Batch Apex Query problem
Hi, I am
working on developing batch apex code for assigning territories in bulk
to leads, accounts, opportunities etc on clicking a custom button
called Run Rules.
My problem is that what will be the query for start method? As I
want all related accounts, opportunities, leads to have territories
assigned to them as per rules in code, how will I map same in Batch
apex? In query, I think we can only extract records of 1 object and
pass to execute batch method. For all accounts, opps, leads what will
be the query?
The skeleton non-working code is as follows:-
global class BatchApexTerritoryAssignmentBulk implements Database.Batchable<SObject>
{
String query;
global database.Querylocator start(Database.batchableContext bc)
{
SObject[] s1 = [select name, id from Account];
SObject[] s2 = [select name, id from Lead];
query = ??;
/*How to create query of records as on click of button all records
associated with territory need to be selected for batch apex. So we
can't create
query only for account or only for lead, how to take both into consideration?*/
return Database.getQueryLocator(query);
}
/*Depending on query parameter needs to be passed in execute method. So what should be 2nd parameter in execute method?*/
global void execute(Database.BatchableContext BC, List<SObject> sobjList)
{
/*If the required sobjList is obtained successfully, then filter out for leads, accounts, etc*/
List<Lead> leadList = new List<Lead>();
for(sobject s : sobjList)
{
if(s.getsObjectType == Lead.sObjectType)
{
Lead l = (Lead)s;
TerritoryAssignmentBulk.runRules(null, null, l, false);//The
method that needs to be called, for lead all others will be null and
boolean false
leadList.add(l);
}
}
update leadList;
List<Account> accList = new List<Account>();
for(sobject s : sobjList)
{
if(s.getsObjectType == Account.sObjectType)
{
Account a = (Account)s;
TerritoryAssignmentBulk.runRules(a, null, null, false);//for account, others will be null and boolean false
accList.add(a);
}
}
update accList;
}
global void finish(Database.BatchableContext BC)
{
}
webservice static String BatchApexMethod()
{
BatchApexTerritoryAssignmentBulk inst1 = new BatchApexTerritoryAssignmentBulk();
Id batchprocessid = Database.executeBatch(inst1);
return '';
}
}
Please assist!
Thanks!
-Vimal
-
- champ_vimal
- October 20, 2009
- Like
- 0
- Continue reading or reply
Update Metadata API call error
Hi,
I have created a java application which tries to update the metadata in SFDC. I used the following snippet:-
CustomObject co = new CustomObject();
String name = "MyCustomObject”;
co.setFullName(name + "__c");
co.setDeploymentStatus(DeploymentStatus.Deployed);
co.setDescription("Created by the Metadata API");
co.setEnableActivities(true);
co.setLabel(name + " Object");
co.setPluralLabel(co.getLabel() + "s");
co.setSharingModel(SharingModel.ReadWrite);
CustomField nf = new CustomField();
nf.setType(FieldType.Text);
nf.setLabel(co.getFullName() + " Name");
co.setNameField(nf);
UpdateMetadata updateMetadata = new UpdateMetadata();
updateMetadata.setMetadata(co);
updateMetadata.setCurrentName(co.getFullName());
com.sforce.soap._2006._04.metadata.AsyncResult[] ars_F = clnt.getMetadatabinding().update(new UpdateMetadata[]{updateMetadata});
But I got the error: 'Must specify a {http://www.w3.org/2001/XMLSchema-instance}type attribute value for the {http://soap.sforce.com/2006/04/metadata}metadata element'
Can someone please assist me in this?
Thanks,
Vimal
-
- champ_vimal
- September 15, 2009
- Like
- 0
- Continue reading or reply
Custom Field Validation Exception - Test Method error
Hello All,
I am writing a test method for a trigger and it gives me failure error during run test saying that there is some custom field validation exception.
The exact failure message is :
'System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, No Step 1 provider is tagged to this job centre: [Jobcentre_Plus__c]'
Please note there is no such validation rules in any of objects I have used in test method. But after going through some information from test method articles, I have even corporated Dml Exception failure using try catch statements and that error disappears!
Now I have different error while running test. It gives me REQUIRED_FIELD_MISSING error at line 54 col 3 for Job_Seeker_Case__c field in Action Plan Object record insert even though I have given the value to it.
My questions are:
1) How can I fix my code?
2) What is the significance of CUSTOM FIELD VALIDATION error even if we have no validations on any of objects concerned?
Request you to please assist me in this!
Here is the code:-
public class testTrgActionAfterUpdateInsert
{
static testMethod void trgActionAfterUpdateInsertMethod()
{
Jobcentre_Plus__c JCP = new Jobcentre_Plus__c(Phone__c='456676',Town_City__c='Mumbai', Street__c='420', region__c = 'Wales',Jobcentre_Plus_Office_Code__c='Off Code 1',JCP_Advisor_Name__c='Vimal Desai',Name = 'Job Centre 1', County__c='Maharashtra',Postcode__c='98765');
try {
insert JCP;
}
catch (DmlException e)
{
//Assert Error Message
System.assert( e.getMessage().contains('Insert failed. First exception on ' +
'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
e.getMessage() );
}
Account JS = new Account(FirstName= 'Jose',LastName= 'Aquilani',NI_Number__c = 'JC522826C',Town_City__c='Mumbai', Street__c='200',County__c='Ker',Postcode__c='12141',Preferred_Method_of_Communication__c='Letter');
//insert JS;
try {
insert JS;
}
catch (DmlException e)
{
//Assert Error Message
System.assert( e.getMessage().contains('Insert failed. First exception on ' +
'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
e.getMessage() );
}
Date date1 =Date.newInstance(2009,08,12);
Provider__c PRO = new Provider__c(name = 'Pro1', Contractor_No__c = 'Cr - 102', Contract_No__c = 'C - 102', Step__c = '2', Can_Claim__c = 'Yes', Type__c = 'tbc', Street__c = 'Strt - 1', Town_City__c = 'Mumbai', County__c = 'County 1', Postcode__c = 'Post Code - 1', Main_Contact__c = JS.OwnerId);
insert PRO;
Job_Seeker_Case__c JSC = new Job_Seeker_Case__c(Job_Seeker__c=JS.id,DWP_PO_No__c='Dwp-123',Jobcentre_Plus__c=JCP.id,Date_of_Referral__c=date1, Step_1_Provider__c = PRO.id);
//insert JSC;
try {
insert JSC;
}
catch (DmlException e)
{
//Assert Error Message
System.assert( e.getMessage().contains('Insert failed. First exception on ' +
'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
e.getMessage() );
}
Action_Plan__c actPlan = new Action_Plan__c(Action_Plan_Start_Date__c = date1, Status__c = 'In Progress', Frequency_of_Contact__c = 'Once a Week', Agreed_Number_of_Weekly_Job_Applications__c = 32, Job_Seeker_Case__c = JSC.id);
insert actPlan;
Action__c actn = new Action__c(Action_Plan__c = actPlan.id, Status__c = 'In Progress', Action_Owner__c = 'act own 1');
insert actn;
System.assertEquals(actPlan.Actions_Last_Updated_Date__c, System.Today());
}
}
Thanks,
Vimal
-
- champ_vimal
- August 16, 2009
- Like
- 0
- Continue reading or reply
List of merge fields names
Hi,
By any means, do we have a list of names of all merge fields in Salesforce? I am seeing that they are widely used in email templates and in VisualForce pages. Would be glad if there is some central location where I can find all or major of merge fields.
Thanks,
Vimal
-
- champ_vimal
- June 29, 2009
- Like
- 0
- Continue reading or reply
Data Loader login error
Hi,
I am getting an error : "Failed to send request to https://www.salesforce.com/services/Soap/u/15.0" while logging into Data Loader.
I have updated proxy settings(Server host: https://www.salesforce.com, proxy host entered etc) and also used security token alongwith normal Salesforce password. As last step, I uninstalled the data loader and installed it again. Still the same error.
Please assist!
Thanks,
Vimal
-
- champ_vimal
- June 19, 2009
- Like
- 0
- Continue reading or reply
System.assertEquals not working in test method
Hi,
I am having problems with System.assertEquals method not working in my test method. This is the trigger and the class with testmethod:-
trigger NoOfEmployeesTrigger on Account (before insert, before update)
{
if(Trigger.isInsert)
{
Account[] accs = Trigger.new;
for(Integer i=0; i<accs.size(); i++)
{
if(accs[i].name.contains('19'))
{
accs[i].NumberOfEmployees = 25;
}
else
accs[i].NumberOfEmployees = 75;
}
}
if(Trigger.isUpdate)
{
Account[] accs = Trigger.new;
for(Integer i=0; i<accs.size(); i++)
{
if(accs[i].name.contains('19'))
{
accs[i].NumberOfEmployees = 25;
}
else
accs[i].NumberOfEmployees = 75;
}
}
}
public class NoOfEmployeesClass
{
static testMethod void NoOfEmployeesTest()
{
Account acc1 = new Account(name = 'Vim_19Jun_acc1');
Account acc2 = new Account(name = 'Vim_20Jun_acc2');
test.startTest();
insert acc1;
insert acc2;
System.assertEquals(25, acc1.NumberOfEmployees);
//System.assertNotEquals(acc2.NumberOfEmployees, 25);
acc2.name = 'Vim_19Jun_acc2';
update acc2;
test.stopTest();
}
}
The Number of employees field is a number field and it is giving error there under Test failures section:-
Method Name | Total Time (ms) | Message | Stack Trace |
---|---|---|---|
NoOfEmployeesClass.NoOfEmployeesTest | 126.0 | System.Exception: Assertion Failed: Expected: 25, Actual: null | Class.NoOfEmployeesClass.NoOfEmployeesTest: line 12, column 3 |
However, if I remove the method the test method works successfully giving 100% code coverage.
Please assist!
Thanks,
Vimal
-
- champ_vimal
- June 19, 2009
- Like
- 0
- Continue reading or reply
Case studies for functionalities and Apex customizations
Hi All,
Can anyone please give me urls/links from where I can have different varieties of case studies/problems to practise on Salesforce functionalities like workflows, approvals, cases, tasks, rules, profiles, etc. Plus, if possible, I also need sample cases for Apex code development where I can try out practising myself the sample cases based on customizations.
(PS: I know about Force.com Cookbook, apart from this if we have anymore illustrations book, then I would be highly obliged.)
Thanks,
-Vimal
-
- champ_vimal
- June 16, 2009
- Like
- 0
- Continue reading or reply
Insert and Update according to Record Type name
Hi,
I am trying to code down Apex script for the case when the account is of particular record type, insert and update some fields. I have done via hard coding record-type id field value and it succeeded in inserting and updating field values but still I want to generalise the code so that the same can be used in all sandboxes and organisations (I may be wrong but from what I have heard and learned, recrod type ids vary in sandbox and production environment for same record type, please let me know if I am wrong).
I have attempted to write the code as shown below. But still it does not work as required(does not insert/update records as per condition of Record Type name).
trigger AccRecTypeMatchAutoPopulateFieldValues on Account (before insert, before update)
{
List<Id> AccIds = new List<Id>();
String Flag;
if(Trigger.isInsert)
{
Id RecId = [Select Id, Name from RecordType where name = 'rec_type1' limit 1].Id;
Account[] newAccs = Trigger.new;
for(Integer i=0; i < newAccs.size(); i++)
{
if(Trigger.new[i].RecordTypeId == RecId)
//for(Account newAccs : Trigger.new)
{
// if(newAccs.RecordTypeId == '01290000000ChWo')
//
newAccs[i].Website = 'http://www.tcs.com';
newAccs[i].BillingStreet = 'Yantra Park';
//a.BillingCity = 'Mumbai';
newAccs[i].BillingState = 'Maharashtra';
newAccs[i].BillingCountry = 'India';
newAccs[i].Fax = '223120';
newAccs[i].Phone = '2230175';
Flag = 'Y';
AccIds.add(newAccs[i].Id);
}
}
if(Flag == 'Y')
{
Account[] accs = [select Id, name from Account where Id in :AccIds];
insert accs;
}
}
if(Trigger.isUpdate)
{
Id RecId = [Select Id, Name from RecordType where name = 'rec_type1' limit 1].Id;
Account[] oldAccs = Trigger.new;
for(Integer i=0; i < oldAccs.size(); i++)
{
if(Trigger.new[i].RecordTypeId == RecId)
//for(Account newAccs : Trigger.new)
{
// if(newAccs.RecordTypeId == '01290000000ChWo')
//
oldAccs[i].Website = 'http://www.tcs.com';
oldAccs[i].BillingStreet = 'Yantra Park';
//a.BillingCity = 'Mumbai';
oldAccs[i].BillingState = 'Maharashtra';
oldAccs[i].BillingCountry = 'India';
oldAccs[i].Fax = '223120';
oldAccs[i].Phone = '2230175';
Flag = 'Y';
AccIds.add(oldAccs[i].Id);
}
}
if(Flag == 'Y')
{
Account[] accs = [select Id, name from Account where Id in :AccIds];
update accs;
}}
}
-
- champ_vimal
- June 15, 2009
- Like
- 0
- Continue reading or reply
Auto Population of fields based on Record type name
Hi,
I am creating an apex trigger which triggers auto population of fields in Account with values based on a particular record type name. However, on saving the trigger it gives no errors neither while testing it on Salesforce. However, ofcourse, the records dont get updated with the values on condition of matching record type. Let me know where am I going wrong in the code below. Please suggest corrective actions accordingly.
Thanks,
Vimal
trigger AccRecTypeMatchAutoPopulateFieldValues on Account (before insert, before update) { if(Trigger.isInsert) { Account[] newAccs = Trigger.new; RecordType rt1 = [select name from RecordType where SobjectType = 'Account' limit 1]; if(rt1.name == 'rec_type1') { for (Account a:newAccs) { a.Website = 'http://www.tcs.com'; a.BillingStreet = 'Yantra Park'; a.BillingCity = 'Mumbai'; a.BillingState = 'Maharashtra'; a.BillingCountry = 'India'; a.Fax = '223120'; a.Phone = '2230175'; } insert newAccs; } } if(Trigger.isUpdate) { Account[] oldAccs = Trigger.new; RecordType rt2 = [select name from RecordType where SobjectType = 'Account' limit 1]; //if (a.RecordType.Name == 'rec_type1') //if(a.Industry == 'Technology') if(rt2.name == 'rec_type1') { for (Account a:oldAccs) { a.Website = 'http://www.tcs.com'; a.BillingStreet = 'Yantra Park'; a.BillingCity = 'Mumbai'; a.BillingState = 'Maharashtra'; a.BillingCountry = 'India'; a.Fax = '223120'; a.Phone = '2230175'; } update oldAccs; } } }
-
- champ_vimal
- June 02, 2009
- Like
- 0
- Continue reading or reply
System.Async Exception : Test failures when I run all tests
Hi,
I have created some batch apex code alongwith other triggers and class/controller codes.
When I run individual test methods on them, I am able to get test success result alongwith nice code coverage %. However when I run all tests together, I get following test failure errors:-
1)System.AsyncException: Database.executeBatch cannot be called from a batch or future method.
2)System.AsyncException: Future method cannot be called from a future method: changeOwners(String, String)
3)System.AsyncException: Future method cannot be called from a future method: getLead_Rollup_Amount(Id)
4)System.AsyncException: Future method cannot be called from a future method: changeOwners(String, String)
Please note again that the exceptions dont come when tested individually.
Please advise on same.
Thanks,
Vimal
- champ_vimal
- December 10, 2009
- Like
- 0
- Continue reading or reply
Lookup field in VisualForce page
Hi,
I have a visualforce page which has a UserRole field which needs to be lookup.
However, I am using custom controller for same. Can you please let me know how can I display lookup field for same in my visualforce page?
Thanks,
Vimal
- champ_vimal
- November 12, 2009
- Like
- 0
- Continue reading or reply
Custom Field Validation Exception - Test Method error
Hello All,
I am writing a test method for a trigger and it gives me failure error during run test saying that there is some custom field validation exception.
The exact failure message is :
'System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, No Step 1 provider is tagged to this job centre: [Jobcentre_Plus__c]'
Please note there is no such validation rules in any of objects I have used in test method. But after going through some information from test method articles, I have even corporated Dml Exception failure using try catch statements and that error disappears!
Now I have different error while running test. It gives me REQUIRED_FIELD_MISSING error at line 54 col 3 for Job_Seeker_Case__c field in Action Plan Object record insert even though I have given the value to it.
My questions are:
1) How can I fix my code?
2) What is the significance of CUSTOM FIELD VALIDATION error even if we have no validations on any of objects concerned?
Request you to please assist me in this!
Here is the code:-
public class testTrgActionAfterUpdateInsert
{
static testMethod void trgActionAfterUpdateInsertMethod()
{
Jobcentre_Plus__c JCP = new Jobcentre_Plus__c(Phone__c='456676',Town_City__c='Mumbai', Street__c='420', region__c = 'Wales',Jobcentre_Plus_Office_Code__c='Off Code 1',JCP_Advisor_Name__c='Vimal Desai',Name = 'Job Centre 1', County__c='Maharashtra',Postcode__c='98765');
try {
insert JCP;
}
catch (DmlException e)
{
//Assert Error Message
System.assert( e.getMessage().contains('Insert failed. First exception on ' +
'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
e.getMessage() );
}
Account JS = new Account(FirstName= 'Jose',LastName= 'Aquilani',NI_Number__c = 'JC522826C',Town_City__c='Mumbai', Street__c='200',County__c='Ker',Postcode__c='12141',Preferred_Method_of_Communication__c='Letter');
//insert JS;
try {
insert JS;
}
catch (DmlException e)
{
//Assert Error Message
System.assert( e.getMessage().contains('Insert failed. First exception on ' +
'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
e.getMessage() );
}
Date date1 =Date.newInstance(2009,08,12);
Provider__c PRO = new Provider__c(name = 'Pro1', Contractor_No__c = 'Cr - 102', Contract_No__c = 'C - 102', Step__c = '2', Can_Claim__c = 'Yes', Type__c = 'tbc', Street__c = 'Strt - 1', Town_City__c = 'Mumbai', County__c = 'County 1', Postcode__c = 'Post Code - 1', Main_Contact__c = JS.OwnerId);
insert PRO;
Job_Seeker_Case__c JSC = new Job_Seeker_Case__c(Job_Seeker__c=JS.id,DWP_PO_No__c='Dwp-123',Jobcentre_Plus__c=JCP.id,Date_of_Referral__c=date1, Step_1_Provider__c = PRO.id);
//insert JSC;
try {
insert JSC;
}
catch (DmlException e)
{
//Assert Error Message
System.assert( e.getMessage().contains('Insert failed. First exception on ' +
'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
e.getMessage() );
}
Action_Plan__c actPlan = new Action_Plan__c(Action_Plan_Start_Date__c = date1, Status__c = 'In Progress', Frequency_of_Contact__c = 'Once a Week', Agreed_Number_of_Weekly_Job_Applications__c = 32, Job_Seeker_Case__c = JSC.id);
insert actPlan;
Action__c actn = new Action__c(Action_Plan__c = actPlan.id, Status__c = 'In Progress', Action_Owner__c = 'act own 1');
insert actn;
System.assertEquals(actPlan.Actions_Last_Updated_Date__c, System.Today());
}
}
Thanks,
Vimal
- champ_vimal
- August 16, 2009
- Like
- 0
- Continue reading or reply
Is there any way to sync Contact Address to the Account Address on a per contact basis
- LStraub
- June 24, 2009
- Like
- 0
- Continue reading or reply
Data Loader login error
Hi,
I am getting an error : "Failed to send request to https://www.salesforce.com/services/Soap/u/15.0" while logging into Data Loader.
I have updated proxy settings(Server host: https://www.salesforce.com, proxy host entered etc) and also used security token alongwith normal Salesforce password. As last step, I uninstalled the data loader and installed it again. Still the same error.
Please assist!
Thanks,
Vimal
- champ_vimal
- June 19, 2009
- Like
- 0
- Continue reading or reply
System.assertEquals not working in test method
Hi,
I am having problems with System.assertEquals method not working in my test method. This is the trigger and the class with testmethod:-
trigger NoOfEmployeesTrigger on Account (before insert, before update)
{
if(Trigger.isInsert)
{
Account[] accs = Trigger.new;
for(Integer i=0; i<accs.size(); i++)
{
if(accs[i].name.contains('19'))
{
accs[i].NumberOfEmployees = 25;
}
else
accs[i].NumberOfEmployees = 75;
}
}
if(Trigger.isUpdate)
{
Account[] accs = Trigger.new;
for(Integer i=0; i<accs.size(); i++)
{
if(accs[i].name.contains('19'))
{
accs[i].NumberOfEmployees = 25;
}
else
accs[i].NumberOfEmployees = 75;
}
}
}
public class NoOfEmployeesClass
{
static testMethod void NoOfEmployeesTest()
{
Account acc1 = new Account(name = 'Vim_19Jun_acc1');
Account acc2 = new Account(name = 'Vim_20Jun_acc2');
test.startTest();
insert acc1;
insert acc2;
System.assertEquals(25, acc1.NumberOfEmployees);
//System.assertNotEquals(acc2.NumberOfEmployees, 25);
acc2.name = 'Vim_19Jun_acc2';
update acc2;
test.stopTest();
}
}
The Number of employees field is a number field and it is giving error there under Test failures section:-
Method Name | Total Time (ms) | Message | Stack Trace |
---|---|---|---|
NoOfEmployeesClass.NoOfEmployeesTest | 126.0 | System.Exception: Assertion Failed: Expected: 25, Actual: null | Class.NoOfEmployeesClass.NoOfEmployeesTest: line 12, column 3 |
However, if I remove the method the test method works successfully giving 100% code coverage.
Please assist!
Thanks,
Vimal
- champ_vimal
- June 19, 2009
- Like
- 0
- Continue reading or reply
Create Roll-up Summary on Campaign Object
I want to create a roll-up summary field on the campaign object that totals opportunity values that meet certain criteria (date range of close date & Record Type).
I am at a loss. Any ideas?
- Collaborative e
- June 16, 2009
- Like
- 0
- Continue reading or reply
Case studies for functionalities and Apex customizations
Hi All,
Can anyone please give me urls/links from where I can have different varieties of case studies/problems to practise on Salesforce functionalities like workflows, approvals, cases, tasks, rules, profiles, etc. Plus, if possible, I also need sample cases for Apex code development where I can try out practising myself the sample cases based on customizations.
(PS: I know about Force.com Cookbook, apart from this if we have anymore illustrations book, then I would be highly obliged.)
Thanks,
-Vimal
- champ_vimal
- June 16, 2009
- Like
- 0
- Continue reading or reply
Insert and Update according to Record Type name
Hi,
I am trying to code down Apex script for the case when the account is of particular record type, insert and update some fields. I have done via hard coding record-type id field value and it succeeded in inserting and updating field values but still I want to generalise the code so that the same can be used in all sandboxes and organisations (I may be wrong but from what I have heard and learned, recrod type ids vary in sandbox and production environment for same record type, please let me know if I am wrong).
I have attempted to write the code as shown below. But still it does not work as required(does not insert/update records as per condition of Record Type name).
trigger AccRecTypeMatchAutoPopulateFieldValues on Account (before insert, before update)
{
List<Id> AccIds = new List<Id>();
String Flag;
if(Trigger.isInsert)
{
Id RecId = [Select Id, Name from RecordType where name = 'rec_type1' limit 1].Id;
Account[] newAccs = Trigger.new;
for(Integer i=0; i < newAccs.size(); i++)
{
if(Trigger.new[i].RecordTypeId == RecId)
//for(Account newAccs : Trigger.new)
{
// if(newAccs.RecordTypeId == '01290000000ChWo')
//
newAccs[i].Website = 'http://www.tcs.com';
newAccs[i].BillingStreet = 'Yantra Park';
//a.BillingCity = 'Mumbai';
newAccs[i].BillingState = 'Maharashtra';
newAccs[i].BillingCountry = 'India';
newAccs[i].Fax = '223120';
newAccs[i].Phone = '2230175';
Flag = 'Y';
AccIds.add(newAccs[i].Id);
}
}
if(Flag == 'Y')
{
Account[] accs = [select Id, name from Account where Id in :AccIds];
insert accs;
}
}
if(Trigger.isUpdate)
{
Id RecId = [Select Id, Name from RecordType where name = 'rec_type1' limit 1].Id;
Account[] oldAccs = Trigger.new;
for(Integer i=0; i < oldAccs.size(); i++)
{
if(Trigger.new[i].RecordTypeId == RecId)
//for(Account newAccs : Trigger.new)
{
// if(newAccs.RecordTypeId == '01290000000ChWo')
//
oldAccs[i].Website = 'http://www.tcs.com';
oldAccs[i].BillingStreet = 'Yantra Park';
//a.BillingCity = 'Mumbai';
oldAccs[i].BillingState = 'Maharashtra';
oldAccs[i].BillingCountry = 'India';
oldAccs[i].Fax = '223120';
oldAccs[i].Phone = '2230175';
Flag = 'Y';
AccIds.add(oldAccs[i].Id);
}
}
if(Flag == 'Y')
{
Account[] accs = [select Id, name from Account where Id in :AccIds];
update accs;
}}
}
- champ_vimal
- June 15, 2009
- Like
- 0
- Continue reading or reply
Auto Population of fields based on Record type name
Hi,
I am creating an apex trigger which triggers auto population of fields in Account with values based on a particular record type name. However, on saving the trigger it gives no errors neither while testing it on Salesforce. However, ofcourse, the records dont get updated with the values on condition of matching record type. Let me know where am I going wrong in the code below. Please suggest corrective actions accordingly.
Thanks,
Vimal
trigger AccRecTypeMatchAutoPopulateFieldValues on Account (before insert, before update) { if(Trigger.isInsert) { Account[] newAccs = Trigger.new; RecordType rt1 = [select name from RecordType where SobjectType = 'Account' limit 1]; if(rt1.name == 'rec_type1') { for (Account a:newAccs) { a.Website = 'http://www.tcs.com'; a.BillingStreet = 'Yantra Park'; a.BillingCity = 'Mumbai'; a.BillingState = 'Maharashtra'; a.BillingCountry = 'India'; a.Fax = '223120'; a.Phone = '2230175'; } insert newAccs; } } if(Trigger.isUpdate) { Account[] oldAccs = Trigger.new; RecordType rt2 = [select name from RecordType where SobjectType = 'Account' limit 1]; //if (a.RecordType.Name == 'rec_type1') //if(a.Industry == 'Technology') if(rt2.name == 'rec_type1') { for (Account a:oldAccs) { a.Website = 'http://www.tcs.com'; a.BillingStreet = 'Yantra Park'; a.BillingCity = 'Mumbai'; a.BillingState = 'Maharashtra'; a.BillingCountry = 'India'; a.Fax = '223120'; a.Phone = '2230175'; } update oldAccs; } } }
- champ_vimal
- June 02, 2009
- Like
- 0
- Continue reading or reply
Static Variables - are they shared by all Salesforce threads within an org?
In the following example, p.FirstRun is set to false inside the trigger.
What happens when :
1. At the same time user 1 is executing this trigger, user 2 is also executing the same trigger? Do they overwrite each other's value?
2. What happens when 10 minutes later someone else needs to execute the same trigger. Is the p.FirstRun set to false by the the first
execution of the trigger? Does the trigger below need to reset p.FirstRun to true when it comes back in the second time for recursion so that a second user
ten minutes later find p.Firstrun as true?
From Salesforce Apex Language reference manual:
Use static variables to store information that is shared within the confines of the class. All instances of the same class share a
single copy of the static variables. For example, all triggers that are spawned by the same request can communicate with each
other by viewing and updating static variables in a related class. A recursive trigger might use the value of a class variable to
determine when to exit the recursion.
A trigger that uses this class could then selectively fail the first run of the trigger:
Suppose you had the following class:
public class p {
public static boolean firstRun = true;
}
trigger t1 on Account (before delete, after delete, after undelete) { if(Trigger.isBefore){ if(Trigger.isDelete){ if(p.firstRun){ Trigger.old[0].addError('Before Account Delete Error'); p.firstRun=false; } } } }
- GoForceGo
- May 05, 2008
- Like
- 0
- Continue reading or reply