-
ChatterFeed
-
4Best Answers
-
1Likes Received
-
0Likes Given
-
10Questions
-
34Replies
Test coverage for .addError and .add statments in trigger
Hi can any one help me out to get test coverage for .addError and .add statments
Below is the trigger and test calss.
Bold line are not covered with the existing test class.
trigger Erroriftwoopportunityareopen on Opportunity (before insert) {
Set <id> setAccWithProspectingOpp = new Set <Id>();//Varaible to hold Account with Prospecting opp
Set <id> setAccId = new Set <Id>();//Varaible to hold Account IDs
if(trigger.isbefore){
if(trigger.isinsert){
//Iterate through opportunity
for(Opportunity o:Trigger.new){
//System.debug('Account Id -->'+o.Accountid);
//Verify account id not null and opportunity stagename is Prospecting
if(o.Accountid != Null && o.StageName == 'Prospecting'){
setAccId.add(o.Accountid);//Account is added to setAccId(Varaible)
}
}
//System.debug('Set of accounts -->'+setAccId);
//Fetch the accounitid of opportunity from aetAccId(Varaible)
for(Opportunity Opp : [Select id,accountid from opportunity where accountid in :setAccId]){
setAccWithProspectingOpp.add(Opp.accountid);//Add opportunity account id in setAccWithProspectingOpp(Variable)
}
//System.debug('Set of accounts with Prosp Opp-->'+setAccWithProspectingOpp);
//Iterate through opportunity object
for(Opportunity o:Trigger.new){
//Chack condition that in setAccWithProspectingOpp(Varaible)contains opportunity account id
if(setAccWithProspectingOpp.contains(o.accountid))
o.addError('This account already has Opportunity with StageName as Prospecting');
}
}
}
}
Test class
@isTest
public class ErroriftwoopportunityareopenTest{
static testMethod void Test(){
User thisUser = [ Select Id from User where Id = :UserInfo.getUserId() ];
Account acc = new Account(Name = 'TestAccount',Rating = 'Hot',Type = 'Prospect');
//update acc;
Opportunity opp = new Opportunity(Name = 'TestOpp',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'Prospecting');
//update opp;
Opportunity opp1 = new Opportunity(Name = 'TestOpp1',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'ClosedWon');
//update opp1;
Opportunity opp2 = new Opportunity(Name = 'TestOpp2',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'ClosedLost');
//update opp2;
Task t = new Task(WhatId=acc.Id,WhoId = opp.Id,Subject = 'Email',Status = 'Completed', Priority ='Normal');
insert t;
Test.startTest();
insert acc;
insert opp;
insert opp1;
insert opp2;
User someOtherUser = [Select Id From User Where Id != :UserInfo.getUserId() And isActive = TRUE LIMIT 1];
system.runAs(someOtherUser){
insert opp;
}
Test.StopTest();
}
}
- Vishnu7700
- September 06, 2013
- Like
- 0
- Continue reading or reply
The page don't show the results
Hello every body, I don't know why can't display the results in my visualforce page. The page don't show error only is empty
Please help me, I try to display the contacts in a family with their benefits
This is my visualforce page
<apex:page StandardController="Sayana__c" extensions="familiaExtension">
<apex:pageBlock title="Beneficios">
<apex:pageBlockTable value="{!BeneficiosTodos}" var="beneficio" cellPadding="3" border="1" columnsWidth="50px,110px,60px,60px,230px" rules="all">
<apex:column value="{!beneficio.Contacto__c}"/>
<apex:column value="{!beneficio.fecha_entrega__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
and this is the apex class
public class familiaExtension {
private final Sayana__c sayana;
private string idSayana;
private final Contact contacto;
private final Beneficio__c[] beneficios;
public familiaExtension(ApexPages.StandardController sayanaController) {
this.sayana = (Sayana__c)sayanaController.getRecord();
idSayana = sayana.id;
}
public List<Beneficio__c> getBeneficiosTodos()
{
for(Contact contact : [SELECT id, Name from Contact where Sayana__c = :idSayana]){
Beneficio__c[] beneficios = contact.Beneficios__r;
}
return beneficios;
}
}
- 1111_forcecom
- September 04, 2013
- Like
- 0
- Continue reading or reply
Rerender Pageblocksection through visualforce checkbox via ajax
I am having a Checkbox on my vf page and what i want is when i click on my chekbox then only my certain pageblocksection/outpanel should be visible.
i am using following code on vf:
<apex:pageBlockSection title="Select Countries"> <apex:inputCheckbox value="{!reUSA}" label="USA"><apex:actionSupport event="onchange" reRender="USASection" id="Us"/></apex:inputCheckbox> </apex:pageBlockSection> <apex:outputPanel id="USASection" rendered="{!reUSA}"> <apex:inputField value="{!abc__c.myfield__c}" /></apex:outputPanel>
Apex code:
public Boolean reUSA{get; set;}
Now i have used various syntax for rendered attribute like: rendered="{!IF(reUSA==true,true,false)}"
OR this rendered={!reUSA=true} but the outpanel is not visible when i click on checkbox.
Onething i am confirmed about is when i click on checkbox ,its value is set to true...and i have even tried to display that value and i get true and onchanging the checkbox ,it shows me false and so on true..false.on further clicking..... but the thing i didn't understand is if its value sets to true/false..then y is it not able to substitute its "true/false" value in rendered attribute... in place of {!reUSA}.
Any suggestion wud be appreciated.. :)
- Dafuel
- August 19, 2013
- Like
- 0
- Continue reading or reply
Save Button's Method Code which when clicked Saves the object and redirects to the parent Object
Hi,
Am new to salesforce, I had customized my org with my requirements, But am facing some problem:
I have a Custom JunctionObject__c which has 2 fileds CustomField1__c master-detail relation to CustomObject1__c and Similarly CustomField2__c master-detail relation to CustomObject2__c.
I had Customized the new edit page to my own VF page i.e. VF1 n used StandardController=”JunctionObject__c ”.
And overriden the "New" button of JunctionObject__c to VF1.
So when we go from CustomObject1__c (PARENT) record we can see the related block JunctionObject__c , NOW when I click the "NEW" button the VF! appears Good. and I insert the data and click Save Button am going to detail page of JunctionObject__c,
But I need to be redirected to the CustomObject1__c detail page of that id.
Here's below is the VF1 page :
<apex:page standardController="JunctionObject__c" extensions="testController"> <apex:sectionHeader title="JunctionObject Edit" subtitle="New JunctionObject" /> <apex:form id="myForm"> <apex:pageBlock title="JunctionObject Edit" mode="edit"> <Apex:pageBlockButtons > <apex:commandButton action="{!save}" value="save"/> <apex:commandButton action="{!cancel}" value="cancel"/> </Apex:pageBlockButtons> <apex:pageBlockSection title="JunctionObject Information" columns="1"> <br/> <apex:pageBlockSectionItem > <apex:outputLabel value="CusomField1"/> <apex:inputField value="{!var.CustomObject1__c}" /> </apex:pageBlockSectionItem> <br/> <apex:pageBlockSectionItem > <apex:outputLabel value="CusomField2"/> <apex:inputField value="{!var.CustomObject2__c}" /> </apex:pageBlockSectionItem> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
And my TestController is as Follows::
public class testController { public JunctionObject__c var {get;set;} public testController(ApexPages.StandardController controller) { var= new JunctionObject__c(); } }
I didn't write any code for save Method, Now Please suggest the code for Save Method which saves the object and redirects it to the parent CustomObject1__c.
I.e. a Save button when clicked saves the inputvalues to the JunctionObject and Redirectes straight away to the previous CustomObject1 from where it came.
Would be very helpful, if provided the code.
Thankyou.
- developerTeam
- August 17, 2013
- Like
- 0
- Continue reading or reply
Google SSO Email Verification Issue
We have implemeted google sso for force.com, through setting an auth provider with open id. it works fine. but in cases where email verification is required, when we entered the verification code and continues it directs to a login error page or an internal server error page. but if we try to login through sso just after that everything works fine and redirects to the home page.
can any1 give an idea to avoid that error page
Thanks
- amilaw
- January 20, 2014
- Like
- 1
- Continue reading or reply
Google Single Sign On
Hi All,
Please tell me the steps to configure salesforce single sign on from google.
Thanks
- amilaw
- December 05, 2013
- Like
- 0
- Continue reading or reply
Changing Salesforce Theme
Hi All
Some developers suggest to create a home page component with some CSS and JAVASCRIPT and put it into the home page layout which will allow us to change the salesforce standard theme. (Blue color theme). Is this recomended. will this kind of thing affect the normal functionality if salesforce.com changed html structure in a new release.
Thanks.
sample for such a CSS and javascript shown below
document.getElementsByTagName('nav')[0].style.border="1px solid white"; document.getElementsByClassName('left')[0].style.visibility = 'hidden'; document.getElementById('phHeaderLogoImage').style.visibility = 'visible'; document.getElementsByClassName('right')[0].style.visibility = 'hidden'; document.getElementsByClassName('multiforce')[0].style.visibility = 'visible'; document.getElementsByTagName('nav')[0].style.borderTopLeftRadius = '.5em'; document.getElementsByTagName('nav')[0].style.borderTopRightRadius = '.5em'; document.getElementsByTagName('nav')[0].style.MozBorderRadiusTopleft = '.5em'; document.getElementsByTagName('nav')[0].style.MozBorderRadiusTopright = '.5em'; document.getElementsByTagName('nav')[0].style.WebkitBorderTopLeftRadius = '.5em'; document.getElementsByTagName('nav')[0].style.WebkitBorderTopRightRadius = '.5em'; <!-- @ author Harpreet Dhillon @ email hsdmail@yahoo.com @ created 06-07-2012 @ free to use and modify, please do not remove this comment. --> <style> .sidebarModuleHeader { background-image: transparent!important; background-color: #3B5998!important; color: #FFFFFF!important; background-image: url(http://www.glittergraphicsite.com/background/pattern/background-pattern-005.jpg)!important; <!-- Upload the file to your static resourse, and change the backround-image's url to the direct link of the static resourse. It is a much better way of using images. Is strongly recommended, there are no secuirty risks. Steps to retireive direct link: 1. Upload image to Static Resource. 2. Click on Static Resource's Name from the list. 3. Right click the View File link on the Static Resource's detail page, and select Copy Link Location. 4. The Static Resource's Link comes in this format: https://na11.salesforce.com/resource/1295402480000/xyz --> background-repeat: repeat!important; background-attachment: fixed!important; } .sfdcBody, #AppBodyHeader, #AppBodyHeader *{ background-image: url(http://www.glittergraphicsite.com/background/pattern/background-pattern-005.jpg)!important; <!-- Upload the file to your static resourse, and change the backround-image's url to the direct link of the static resourse. It is a much better way of using images. Is strongly recommended, there are no secuirty risks. Steps to retireive direct link: 1. Upload image to Static Resource. 2. Click on Static Resource's Name from the list. 3. Right click the View File link on the Static Resource's detail page, and select Copy Link Location. 4. The Static Resource's Link comes in this format: https://na11.salesforce.com/resource/1295402480000/xyz --> background-repeat: repeat!important; background-attachment: fixed!important; background-color: none!important; color: #FFFFFF!important;} #AppBodyHeader{ background-image: none!important; } .tabNavigation .allTabsArrow, .tabMenu .allTabsArrow { background-image: url("/img/alohaSkin/addTabs.png")!important; height: 12px !important; width: 12px !important; } <!--The below mentioned line removes the Logo from the page's top left corner. Remove it in case its not required--> #phHeaderLogoImage {display:none!important;} </style>
- amilaw
- December 03, 2013
- Like
- 0
- Continue reading or reply
Changes to Financial Force
Hi All,
We need to do some modifications for the financial force app.
For example changing the pages for adding sales invoices.
changing the existing page is not possible as it is a managed package. tried to created a new page with existing visualforce markups. but extensions are not visible.
are there any approaches other than developing page from the scratch ?
Thanks
- amilaw
- November 20, 2013
- Like
- 0
- Continue reading or reply
Developer Console Test Coverage Doesn't Work
Hi All,
I have no way to find what line are covered and what lines are not in a set of apex classes as they are not shown in the developer console test coverage class list.
Even after running all test classes.
- amilaw
- October 29, 2013
- Like
- 0
- Continue reading or reply
Class Code Coverage Page
Hi All,
Where can we get the couloured code coverage page for a class. link is not there any more. its in the developer console. but it doesnt work properly for large classes
Thanks
- amilaw
- October 22, 2013
- Like
- 0
- Continue reading or reply
Avoid Sharing to users who have no access to the object
Hi all,
Is there a way to avoid sharing records fro users who dont have access to the object.
in soql even we used with sharing keyword, records are retrieved for the users who have sharing records but not read access in profile
- amilaw
- September 06, 2013
- Like
- 0
- Continue reading or reply
Avoid Sharing to users who have no access to the object
His all,
Is there a way to avoid sharing records fro users who dont have access to the object.
in soql even we used with sharing keyword, records are retrieved for the users who have sharing records but not read access in profile
- amilaw
- September 06, 2013
- Like
- 0
- Continue reading or reply
First error: Unable to write to any of the cursor stores in the alloted time
Hi All,
Has anyone has an idea about this error message.
First error: Unable to write to any of the cursor stores in the alloted time (15000 msec): 65281 bytes, path: T/00DE0000000YAqTMAW/R/01gE000000GbfERIAZ/0.cursor
Thanks
- amilaw
- August 14, 2013
- Like
- 0
- Continue reading or reply
Salesforce Public Group Limit
Hi All,
Is there a limit of number public groups which can be available in an org ?
For a example in a company there are 5000 users. and can have 1000 teams.
records should be shared within the teams.
for each team create a public group consist of team members and do the apex sharing for those groups.
will this approach cause any problems ?
Thanks in advance.
- amilaw
- August 01, 2013
- Like
- 0
- Continue reading or reply
Google SSO Email Verification Issue
We have implemeted google sso for force.com, through setting an auth provider with open id. it works fine. but in cases where email verification is required, when we entered the verification code and continues it directs to a login error page or an internal server error page. but if we try to login through sso just after that everything works fine and redirects to the home page.
can any1 give an idea to avoid that error page
Thanks
- amilaw
- January 20, 2014
- Like
- 1
- Continue reading or reply
Changes to Financial Force
Hi All,
We need to do some modifications for the financial force app.
For example changing the pages for adding sales invoices.
changing the existing page is not possible as it is a managed package. tried to created a new page with existing visualforce markups. but extensions are not visible.
are there any approaches other than developing page from the scratch ?
Thanks
- amilaw
- November 20, 2013
- Like
- 0
- Continue reading or reply
Developer Console Test Coverage Doesn't Work
Hi All,
I have no way to find what line are covered and what lines are not in a set of apex classes as they are not shown in the developer console test coverage class list.
Even after running all test classes.
- amilaw
- October 29, 2013
- Like
- 0
- Continue reading or reply
Class Code Coverage Page
Hi All,
Where can we get the couloured code coverage page for a class. link is not there any more. its in the developer console. but it doesnt work properly for large classes
Thanks
- amilaw
- October 22, 2013
- Like
- 0
- Continue reading or reply
Avoid Sharing to users who have no access to the object
His all,
Is there a way to avoid sharing records fro users who dont have access to the object.
in soql even we used with sharing keyword, records are retrieved for the users who have sharing records but not read access in profile
- amilaw
- September 06, 2013
- Like
- 0
- Continue reading or reply
Test coverage for .addError and .add statments in trigger
Hi can any one help me out to get test coverage for .addError and .add statments
Below is the trigger and test calss.
Bold line are not covered with the existing test class.
trigger Erroriftwoopportunityareopen on Opportunity (before insert) {
Set <id> setAccWithProspectingOpp = new Set <Id>();//Varaible to hold Account with Prospecting opp
Set <id> setAccId = new Set <Id>();//Varaible to hold Account IDs
if(trigger.isbefore){
if(trigger.isinsert){
//Iterate through opportunity
for(Opportunity o:Trigger.new){
//System.debug('Account Id -->'+o.Accountid);
//Verify account id not null and opportunity stagename is Prospecting
if(o.Accountid != Null && o.StageName == 'Prospecting'){
setAccId.add(o.Accountid);//Account is added to setAccId(Varaible)
}
}
//System.debug('Set of accounts -->'+setAccId);
//Fetch the accounitid of opportunity from aetAccId(Varaible)
for(Opportunity Opp : [Select id,accountid from opportunity where accountid in :setAccId]){
setAccWithProspectingOpp.add(Opp.accountid);//Add opportunity account id in setAccWithProspectingOpp(Variable)
}
//System.debug('Set of accounts with Prosp Opp-->'+setAccWithProspectingOpp);
//Iterate through opportunity object
for(Opportunity o:Trigger.new){
//Chack condition that in setAccWithProspectingOpp(Varaible)contains opportunity account id
if(setAccWithProspectingOpp.contains(o.accountid))
o.addError('This account already has Opportunity with StageName as Prospecting');
}
}
}
}
Test class
@isTest
public class ErroriftwoopportunityareopenTest{
static testMethod void Test(){
User thisUser = [ Select Id from User where Id = :UserInfo.getUserId() ];
Account acc = new Account(Name = 'TestAccount',Rating = 'Hot',Type = 'Prospect');
//update acc;
Opportunity opp = new Opportunity(Name = 'TestOpp',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'Prospecting');
//update opp;
Opportunity opp1 = new Opportunity(Name = 'TestOpp1',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'ClosedWon');
//update opp1;
Opportunity opp2 = new Opportunity(Name = 'TestOpp2',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'ClosedLost');
//update opp2;
Task t = new Task(WhatId=acc.Id,WhoId = opp.Id,Subject = 'Email',Status = 'Completed', Priority ='Normal');
insert t;
Test.startTest();
insert acc;
insert opp;
insert opp1;
insert opp2;
User someOtherUser = [Select Id From User Where Id != :UserInfo.getUserId() And isActive = TRUE LIMIT 1];
system.runAs(someOtherUser){
insert opp;
}
Test.StopTest();
}
}
- Vishnu7700
- September 06, 2013
- Like
- 0
- Continue reading or reply
- softForce2014
- September 05, 2013
- Like
- 0
- Continue reading or reply
The page don't show the results
Hello every body, I don't know why can't display the results in my visualforce page. The page don't show error only is empty
Please help me, I try to display the contacts in a family with their benefits
This is my visualforce page
<apex:page StandardController="Sayana__c" extensions="familiaExtension">
<apex:pageBlock title="Beneficios">
<apex:pageBlockTable value="{!BeneficiosTodos}" var="beneficio" cellPadding="3" border="1" columnsWidth="50px,110px,60px,60px,230px" rules="all">
<apex:column value="{!beneficio.Contacto__c}"/>
<apex:column value="{!beneficio.fecha_entrega__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
and this is the apex class
public class familiaExtension {
private final Sayana__c sayana;
private string idSayana;
private final Contact contacto;
private final Beneficio__c[] beneficios;
public familiaExtension(ApexPages.StandardController sayanaController) {
this.sayana = (Sayana__c)sayanaController.getRecord();
idSayana = sayana.id;
}
public List<Beneficio__c> getBeneficiosTodos()
{
for(Contact contact : [SELECT id, Name from Contact where Sayana__c = :idSayana]){
Beneficio__c[] beneficios = contact.Beneficios__r;
}
return beneficios;
}
}
- 1111_forcecom
- September 04, 2013
- Like
- 0
- Continue reading or reply
Show list element in two colums
Hi
Ihave list which i want to show in two columns only.
Suppose My list have 1,2,3,4,5,6
repeater display like this
1
2
3
4
5
6
I want layout like ..
1 2
3 4
5 6
Thanks & Regards
Ishan Sharma
- Ishan K Sharma
- September 04, 2013
- Like
- 0
- Continue reading or reply
How to get a rich text area Content
Hi All,
I need to get the content of Rich Text Area Field without HTML markup when i query the field. Is there any method to get the text data excluding the markup?
Thank you in Advance,
Best Regards,
NHK
- NHK
- September 03, 2013
- Like
- 0
- Continue reading or reply