• NTP
  • NEWBIE
  • 30 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 8
    Replies

trigger AccountDuplicateTrigger on Account (before insert,before update)

{    

for(Account a:Trigger.New)    

{     List<Account> acc=new List<Account>();    

acc=[select id from Account where Name=:a.Name and Rating=:a.Rating];

    if(acc.size()>0)        

{        

acc.Name.addError('you cannot create duplicate Account');    

}

 

}

}

Hi,

 

Is calling a batch class from a trigger best practice?

 

Thanks in Advance

  • April 11, 2013
  • Like
  • 0

Hi i am trying to learn unit testing in salesforce. Below is the code of my controller class. The lines marked as red are not getting covered, can any one suggest me how to do it ? Thanks in advance.

public class RadioButton {
public List<contact> selectcon=new List<contact>();
contact con;
public string selectconid;
Public List<contact> getAllContacts()
{
List<contact> allcons = [Select Id,FirstName,LastName,Email,Phone from Contact LIMIT 10];
return allcons;
}
Public void selectcon()
{
string selectconid = System.currentPagereference().getParameters().get('conid');

con = [Select Id,FirstName,LastName,Email,Phone from Contact where Id=:selectconid limit 1];

selectcon.add(con);

}
Public List<contact> getselectedContact()
{
return selectcon;
}

}

I need to create a flag to identify when the permanent address is different from the temporary address.

 

I would appreciate if someone can explain me what this flag is. I understand is a Boolean operation insert in the Apex code but not sure how to do it or

how it works.

 

Thanks!

  • November 14, 2013
  • Like
  • 0

I am getting this error on a VF page :

 

This page is redirected from another controller class : The details are coming on the URL but on the page it is displaying error as :Page DetailController does not exist 

 

External Controller Class : Method :

 

public PageReference SaveChanges()

{
String OppId = ApexPages.currentPage().getParameters().get('Id');
Splits__c LitOrd = new Splits__c();
DSObj = new List<Splits__c>();
LitOrd.Opportunity__c= Opp.id ;
DSObj.add(LitOrd);
insert DSObj;
insert OppTeam;
PageReference pageRef = new PageReference('/apex/DetailController?Id='+opp.Id);
return pageRef;

}

 

--------------------------------------

 

VF page :

<apex:page controller="DetailController" tabstyle="Opportunity">
<apex:form >
<apex:pageBlock title="Region Details">
<apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
<apex:column headerValue="Ident">
<apex:outputText value="{!wrapper.ident}"/>
</apex:column>
<apex:column headerValue="Region">
<apex:inputField value="{!wrapper.MSalesO.Region__c}"/>
</apex:column>
</apex:pageBlockTable>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlock>
</apex:form>
</apex:page>

--------------------------------------

 

Controller Class :

public class DetailController
{

public List<SOWrapper> wrappers {get; set;}

public static Integer addCount {get; set;}
private Integer nextIdent=0;

public DetailController()
{
wrappers=new List<SOWrapper>();
for (Integer idx=0; idx<5; idx++)
{
wrappers.add(new SOWrapper(nextIdent++));
}
}
public void addRows()
{
for (Integer idx=0; idx<addCount; idx++)
{
wrappers.add(new SOWrapper(nextIdent++));
}
}

public PageReference save()
{
List<Order__c> MSO=new List<Order__c>();
for (SOWrapper wrap : wrappers)
{
MSO.add(wrap.MSalesO);
}

insert MSO;

return new PageReference('/' + Schema.getGlobalDescribe().get('Order__c').getDescribe().getKeyPrefix() + '/o');
}

public PageReference SaveDS()

{
return null;
}
public class SOWrapper
{
public Order__c MSalesO {get; private set;}
public Integer ident {get; private set;}

public SOWrapper(Integer inIdent)
{
ident=inIdent;
MSalesO=new Order__c(Opportunity__c='006f0000003afa5' + ident);
}
}

}

trigger AccountDuplicateTrigger on Account (before insert,before update)

{    

for(Account a:Trigger.New)    

{     List<Account> acc=new List<Account>();    

acc=[select id from Account where Name=:a.Name and Rating=:a.Rating];

    if(acc.size()>0)        

{        

acc.Name.addError('you cannot create duplicate Account');    

}

 

}

}

So, if I have seperate apex classes that have the same method names and I invoke the method name from the button on a visualforce page, how does it know which apex class to invoke from?

 

In addition, is it possible to have it invoke the method from the wrong class?

 

Thanks!

When I click on command button,I want one pgblcksection to be refreshed but it's not working if the page has required="true". It should be filled only before I click save only..How to resolve???

 

<apex:page standardController="Account">
<apex:form >
<apex:pageblock >
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2" >
<apex:inputField value="{!account.phone}" required="true"/>

</apex:pageBlockSection>

<apex:pageBlockSection >
<apex:inputField value="{!account.name}"/>
<apex:inputField value="{!account.type}"/>

</apex:pageBlockSection>

<apex:commandButton value="test" reRender="results" immediate="true"/>
<apex:outputPanel id="results">
<apex:pageBlockSection >{!(account.Name+account.type)}</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageblock>
</apex:form>
</apex:page>

  • March 19, 2013
  • Like
  • 0

To design a drop down list box (i.e) Picklist in visualforce is it necessary to create a custom object to store picklist values?

Hi,

I tried validating the <apex:selectRadio> component. But I am unable to validate the field. Please help me how to achieve this either from javascript or jquery. The error should display on the top of the page. Any ideas/hints can appreciate.

 

 

 

 

 

 

Thanks.

 

 

 

-Shiva Kumar