• sanjaypatidar
  • NEWBIE
  • 130 Points
  • Member since 2012

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 28
    Replies

Is it possible that a Trigger can be deployed on the production without test class. I have on Trigger which was built in 2009 and I do not see any test class associated to it on the production.

 

I find this weird, can Sales force allow that?

This Trigger looks like this:-

 

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

trigger AccountCreateTrigger on Account (before insert) {
for (Account acc: Trigger.new)
     {Account [] accs = [SELECT Name FROM Account WHERE Name = :acc.Name LIMIT 1];
      if (accs.size() > 0 ) //if account already exists, block and show the information on the page
         {acc.addError('Account  \'' + accs[0].Name +  '\' already exists. Please use existing account or contact your Salesforce Administrator for assistance.'); }
     }
}

I am trying to remove the hover over link (in blue) and just display the output i.e. the name not the id

 

   <tr>
                 <td id="label">
                    Sales Rep
                 </td>
                <td id="REP">
                    <apex:outputField value="{!Opportunity.OwnerId}"/>
                 </td>
            </tr>

 

Using outputText displays the Id, which I don't want.

 

I'm wondering two options here

 

1. Some kind of inline style override - ???

 

2. Use workflow rule to copy the value

 

Any help, really appreciated.

My trigger is this:

 

trigger RBOppClone on Opportunity (after update) {
        
        Set<Opportunity> oppSet = new Set<Opportunity>();
        for (Opportunity oppRec: trigger.new) {
            oppSet.add(oppRec);
        }
        
        for (Opportunity oppRec: oppSet) {
            Opportunity oldOpp = trigger.oldMap.get(oppRec.Id);
            if (oppRec.Product_Sold__c == 'Business Product' &&
               oppRec.StageName == 'Stage 5 - Closed - Won' &&
               oldOpp.StageName != 'Stage 5 - Closed - Won') {
                Opportunity newOpp = oppRec.clone();
                newOpp.StageName = 'Referral Credit - Dummy Stage';
                if (oppRec.Amount == null || oppRec.Amount < 50.00) {
                    newOpp.Amount = 500;
                } else {
                    newOpp.Amount = 1000;
                }
                insert newOpp;
            }
        }

}

 

Sometimes 2 opportunities are inserted instead of one in the same update. Anyone know why this might be happening? Also, I'm aware this trigger isn't bulk-uploads-safe.

  • April 18, 2012
  • Like
  • 0
ErrorError: Compile Error: AND operator can only be applied to Boolean expressions at line 15 column 40

 

this is what it say all the time. how can it b fixed?


trigger PreventEngagementsFromDelete on Engagement__c(before Delete){


RecordType[] RT = [Select Name From RecordType Where sObjectType = 'engagement__c' and Name = 'Interest Form' and isActive = true LIMIT 1];


for(Engagement__c e : trigger.new){

   if(!rt.isEmpty()){

      if(e.RecordTypeID = RT[0].id && e.Status__c = 'Prospect')

           e.addError('You cannot delete this record');

    }else{

           e.addError('Contact System Admin, there was an error finding the correct RecordType for this validation');

    }

 

}

 

  • April 17, 2012
  • Like
  • 0

 want to update another object say  1."account_master__c" from  2nd"ATM_transacction__c".writing after insert trigger in 2nd object.please look at the code.

 

trigger atm2 on ATM_Transaction__c (after insert)

{

for(atm_transaction__c atm: trigger.new)
{
aggregateResult a=[select sum(amount__c) s from atm_transaction__c where
account_id__c=:atm.account_id__c];

double i=(double)a.get('s');

account_master__c am=new account_master__c();
am=[select id, balance__c from account_master__c where
account_idm__c=:atm.accout_id__c]

if(am.balance__c > i){
am.balance__c=am.balance__c -i;
}
//update am;
}
update am;

}

 

where i wenr wrong.

thanks in advance.


I am trying to chatter mention auto complete where after typing @ and two characters, the component can bring up the user names. Can anyone help me how with how to activate the AutoComplete after a specific character has been entered ?

Hi,


I have created a Opportunity Wizard (5 Steps / Pages), on one page I have a product selection page which allows users to select multiple products using pagination (Offset Used).

 

My Issue is that when the user navigates from previous page to Product Selection page and selects products and moves to the Page2 of the PAGINATION the checkboxes of the previous selection is shown as checked, where as I debugged the table and it shows value as false.

 

Stangely - If i load the pagination page alone, this does not happen. I am not sure if its cache or something else.. I used cache="false" as well but still same issue.

 

My VF Page Code  - 

      		<apex:pageBlockButtons >
				<apex:commandButton action="{!step3}" value="Previous"/>
	          	<apex:commandButton action="{!step5}" value="Next"/>
				<apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true"/>
			</apex:pageBlockButtons>


				<apex:outputPanel id="MainPanel">
					<apex:outputPanel id="ProductSelectionPanel" rendered="{!!processSelectedPriceBookEnteries && pricebookSelected}">
						<div class="header">Select Products</div>
						<apex:actionStatus id="stat">
			            	<apex:facet name="start"> 
			                    <apex:outputPanel layout="block" styleClass="message infoM4">
			                        <apex:panelGrid columns="2" styleClass="messageTable" columnClasses="messageCell" style="padding:0px;margin:0px;">
			                            <apex:panelGroup >
			                                <img class="loadingIcon" src="/s.gif"/>
										</apex:panelGroup>
										<apex:panelGroup >
			                                <div class="messageText">Please wait...</div>
										</apex:panelGroup>
									</apex:panelGrid>
								</apex:outputPanel>
							</apex:facet>
			                    
							<apex:facet name="stop">
                        		<apex:pageblockTable value="{!OpportunityProducts}" var="pbe" id="pbTable" rendered="{!!processSelectedPriceBookEnteries}">
									<apex:column >
			                            <apex:facet name="header">
				                            <script>
				                                //Not sure why adding this resolves the issue of the header checkbox always checked.. Something Strange !!
											</script>
											<apex:inputcheckbox selected="{!selectall}">
												<apex:actionSupport event="onchange" action="{!toggleSelection}" reRender="MainPanel"/>
			                                </apex:inputcheckbox>
										</apex:facet>
										<apex:inputCheckbox value="{!pbe.checked}">
			                            	<apex:actionSupport event="onchange"  reRender="MainPanel"/>
										</apex:inputCheckbox>
									</apex:column> 

									<apex:column >
										<apex:facet name="header">Product Name</apex:facet>
						                <apex:outputField value="{!pbe.PBookEntry.Product2Id}"/>
									</apex:column>
						                
						           <apex:column >
						                <apex:facet name="header">Product Code</apex:facet>
										<apex:outputField value="{!pbe.PBookEntry.ProductCode}"/>
									</apex:column>
						                
									<apex:column >
						            	<apex:facet name="header">Is Active</apex:facet>
						                <apex:outputField value="{!pbe.PBookEntry.IsActive}"/>
									</apex:column>
						                
						            <apex:column >
						            	<apex:facet name="header">Unit Price</apex:facet>
						                <apex:outputField value="{!pbe.PBookEntry.UnitPrice}"/>
									</apex:column>
								</apex:pageblockTable>
							</apex:facet>
						</apex:actionStatus>
							
						<br/>
			            	
			            <div align="center">
							<ul class="menu">
								<li class="rollover" id="first"><apex:commandLink rendered="{!NOT(pageNumber == 0)}" reRender="MainPanel" action="{!firstPage}" immediate="true" title="First Page" status="stat"/></li>
								<li class="rollover" id="previous"><apex:commandLink rendered="{!NOT(pageNumber == 0)}" reRender="MainPanel" action="{!previous}" immediate="true" title="Previuos" status="stat"/></li>
								<li style=" margin-right: 10px;"> <apex:outputText >Page {!pageNumber+1} of {!noOfPages}</apex:outputText></li>
								<li class="rollover" id="next"><apex:commandLink rendered="{!NOT(pageNumber == noOfPages -1)}" reRender="MainPanel" action="{!next}" immediate="true" title="Next" status="stat"/></li>
								<li class="rollover" id="last"><apex:commandLink rendered="{!NOT(pageNumber == noOfPages -1)}" reRender="MainPanel" action="{!lastPage}" immediate="true" title="Last" status="stat"/></li>
							</ul>
							<span>
								<apex:commandLink value="Process Selected" rendered="{!productsSelected}" rerender="MainPanel" action="{!QueryOpportunityLineItem}" immediate="true" styleClass="AddrowButton" title="Process Selected" style="color: white; float: right;">
							    	<apex:param name="processSelected" value="true" assignTo="{!processSelectedPriceBookEnteries}" />
								</apex:commandLink>
							</span> 
						</div>
					</apex:outputPanel>

kindly let me know if anyone has seen similar behaviour with wizard and pagination together ?

 

Thanks in Advance,

Sanjay

Hi All,

 

I have written a class where i am passing an Object and getting the details of all the fields in the object. This class runs fine when the user have access to the object/fields, but if the user do not have access to the object/fields returns null.

 

Code Below  -

        // Get a map of field name and field token
        Map<String, Schema.SObjectField> fMap = Schema.getGlobalDescribe().get(objectName.toLowerCase()).getDescribe().Fields.getMap();
        list<string> selectFields = new list<string>();
         system.debug('***- '+fMap);
        if (fMap != null)
            {
            for (Schema.SObjectField ft : fMap.values())
                { // loop through all field tokens (ft)
                system.debug('LLL');
                Schema.DescribeFieldResult fd = ft.getDescribe(); // describe each field (fd)
                if (fd.isCreateable())
                    { // field is creatable
                      // I need to add all the fields in the object which can be created irrespective of whether the logged in user has read access or write access on it or even for that matter if he even do not have access on the Object. 
                    selectFields.add(fd.getName());
                    }
                }
            }

 // I need to add all the fields in the object which can be created irrespective of whether the logged in user has read access or write access on it or even for that matter if he even do not have access on the Object. 

 

Thanks in Advance,

Sanjay

Hi All,

 

I have a requirement where I need to read a set of values from one object and set it to the new record before insert. The values in the Objects can be of 3 types (String, Integer and System Methods)

 

Example -

 

Field LabelAPI NameDefault ValueData Type
StageStageNameNegotiation/ReviewString
QuantityTotalOpportunityQuantity25Integer
User IdCurrentUserId__cuserinfo.getUserId()System Method

 

So I read the data from here and set the Default value from the above table and set it in a SObject (Map). as below - 

			for(integer i=0; i<exceptions.size(); i++)
				{
				if(exceptions.get(i).Data_Type__c == 'String')
					{
					System.debug('Field Name - ['+exceptions.get(i).API_Name__c + '] with Value ['+ exceptions.get(i).Default_Value__c+']');
					cloneId.put(exceptions.get(i).API_Name__c, exceptions.get(i).Default_Value__c); 
					}

				if(exceptions.get(i).Data_Type__c == 'Integer')
					{
					System.debug('Field Name - ['+exceptions.get(i).API_Name__c + '] with Value ['+ Integer.valueof(exceptions.get(i).Default_Value__c.trim())+']');	
					cloneId.put(exceptions.get(i).API_Name__c,  Integer.valueof(exceptions.get(i).Default_Value__c.trim())); 
					}

 

But when I try to pass the System Method records, it is considering it as a String and not the real value from the method.

 

I am using the below line for it.

 

if(exceptions.get(i).Data_Type__c == 'System Method')

{

cloneId.put(exceptions.get(i).API_Name__c, exceptions.get(i).Default_Value__c);

}

 

where as if I simply put it explicity, it works Like - cloneId.put(exceptions.get(i).API_Name__c, userinfo.getUserId());

 

My Question is that why the value of the userinfo.getUserId() is not getting calculated before it sets it in the Map.

 

Any pointers please..

 

Thanks,
Sanjay 

 

All,

I believe I am missing something here.  I have a class that starts out with this...

public with sharing class Lilly_QR_PDF {

 And contains this function...

//Get all the accessible fields for a given object
    public static String getAccessibleFields(String objName){
        String fields = '';        
        Map<String,Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(objName.toLowerCase()).getDescribe().Fields.getMap();         
        if(fieldMap != null){
            for(Schema.Sobjectfield ft : fieldMap.values()){
                Schema.DescribeFieldResult fd = ft.getDescribe();
                if(fd.isAccessible()){
                    fields = fields + fd.getName() + ',';
                }
            }
            if(fields.length() > 0){
                fields = fields.subString(0,fields.length()-1);
            }else{
                fields = 'id';
            }
        }else{
            System.debug('FieldMap was null');
        }
        return fields;
    }

 As you can see that should only return the fields that come back with isAccessible equal to true. 

When I call the page with this heading...

<apex:page controller="Lilly_QR_PDF" renderAs="PDF" showHeader="false" sidebar="false" standardStyleSheets="false">

 It grabs fields that the user I am currently logged in with does not have access to.  I am sure I am just missing something or misunderstanding some basic security rules here, but I have looked at can not figure out what is going on.  Any help would be appreciated. 

Hi, Need help in trigger.

 

Whenver a ticket is created through email to case, the ticket is created in the name of my company's administrator and contact name and email shows up as her instead of who actually create the ticket. Although the actual contact who emailed for that ticket exist in our salesforce account.

 

How I can create a trigger to assign the contact name and email for that particular person who created the ticket through email to case instead of my company's administrator? Please help.

 

Now the code coverage is 100% and i am trying to deploy that to production. I am using package to push this trigger and the test class to production. When i try to install the package in the production is shows package installation error saying that

"Duplicate RelationshipNameCustom Field DefinitionsThe relationship name "Cases__r" is already used by custom field Case.Opportunity__c. Please rename existing relationship name."

When i try to put the trigger and test class in the package this custom field automatically added to this package. Not sure why.

please advise.

Is it possible that a Trigger can be deployed on the production without test class. I have on Trigger which was built in 2009 and I do not see any test class associated to it on the production.

 

I find this weird, can Sales force allow that?

This Trigger looks like this:-

 

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

trigger AccountCreateTrigger on Account (before insert) {
for (Account acc: Trigger.new)
     {Account [] accs = [SELECT Name FROM Account WHERE Name = :acc.Name LIMIT 1];
      if (accs.size() > 0 ) //if account already exists, block and show the information on the page
         {acc.addError('Account  \'' + accs[0].Name +  '\' already exists. Please use existing account or contact your Salesforce Administrator for assistance.'); }
     }
}

I am trying to remove the hover over link (in blue) and just display the output i.e. the name not the id

 

   <tr>
                 <td id="label">
                    Sales Rep
                 </td>
                <td id="REP">
                    <apex:outputField value="{!Opportunity.OwnerId}"/>
                 </td>
            </tr>

 

Using outputText displays the Id, which I don't want.

 

I'm wondering two options here

 

1. Some kind of inline style override - ???

 

2. Use workflow rule to copy the value

 

Any help, really appreciated.

My trigger is this:

 

trigger RBOppClone on Opportunity (after update) {
        
        Set<Opportunity> oppSet = new Set<Opportunity>();
        for (Opportunity oppRec: trigger.new) {
            oppSet.add(oppRec);
        }
        
        for (Opportunity oppRec: oppSet) {
            Opportunity oldOpp = trigger.oldMap.get(oppRec.Id);
            if (oppRec.Product_Sold__c == 'Business Product' &&
               oppRec.StageName == 'Stage 5 - Closed - Won' &&
               oldOpp.StageName != 'Stage 5 - Closed - Won') {
                Opportunity newOpp = oppRec.clone();
                newOpp.StageName = 'Referral Credit - Dummy Stage';
                if (oppRec.Amount == null || oppRec.Amount < 50.00) {
                    newOpp.Amount = 500;
                } else {
                    newOpp.Amount = 1000;
                }
                insert newOpp;
            }
        }

}

 

Sometimes 2 opportunities are inserted instead of one in the same update. Anyone know why this might be happening? Also, I'm aware this trigger isn't bulk-uploads-safe.

  • April 18, 2012
  • Like
  • 0

Hi,

 

  I have written the following trigger.

 

 

trigger OpportunityStageToCaseStatus on Opportunity (after update) {
/////////////////////////////////
// This Trigger updates the Case status of the related opportunity//
/////////////////////////////////

if(trigger.isAfter && trigger.isUpdate) {

// Create List of Cases that relate to this Opportunity
List<Case> lstCasesToCheck = [SELECT Opportunity__c, Status FROM Case WHERE Opportunity__c IN :trigger.new];
List<Case> lstCasesToUpdate = new List<Case>();

for(Opportunity o : trigger.new) {

// Check to see if the StageName has changed

{
if(trigger.newMap.get(o.Id).StageName != trigger.oldMap.get(o.Id).StageName)
// Loop through Cases
for(Case c : lstCasesToCheck) {
if(o.StageName == 'Closed/Won') {
c.Status= 'Resolved';
lstCasesToUpdate.add(c);
}
}

}

}

// Bulk DML
if(lstCasesToUpdate.size() > 0) { update lstCasesToUpdate; }

}
}

 

 

and wrote the following test class.

 

@isTest
private class OpportunityStageToCaseStatustest {

static testMethod void myUnitTest() {

case c=new case(Status='New',Origin='Email',Opportunity__c='006V0000002fHfU');
insert c;
opportunity o= new opportunity(id='006V0000002fHfU',StageName = 'Closed/Won');
update o;
c.status='Resolved';
update c;


}
}

 

But it shows only 60% code coverage. so i am not able to push the code to production. Any advise on this please.

Thanks!

I'm writing a test class that creates a lead and converts it.  On conversion 2 new contacts are created through a trigger using data from the lead and it's this contact creation that I'm testing for.

 

The save result reports the following:  "Can not select a person account"

 

My contacts are being created using the account Id of the account created on conversion,  so,  I assume it's this account that is being created as a person account.  How can I ensure that the account created on conversion is a business account?

 

The code works perfectly well when I'm running it through the GUI and as far as I can tell,  I'm creating the lead using the same recordtype and other data.

 

Any thoughts?

Hi,

 

I have a custom button "Submit Order" which simple change Opportunity Stage.

But i want to add some validation check before changing Stage

 

Here is my apex class

 

global class SubmitOrder {

    public SubmitOrder(ApexPages.StandardController controller)
    {
    }
   
    Webservice static string Submit(string oppId)
    {
        string message = '';
        try
        {
            List<Opportunity> listOpp = new List<Opportunity>();
            Opportunity oppNew = [SELECT id, StageName, Destination_Zone__c, Sold__c  FROM Opportunity WHERE Id = :oppId];
    
            boolean flag = true;
            if(oppNew.StageName!= 'To Be Searched' && oppNew.StageName != 'Search')
            {
                oppNew.StageName.addError('Stage should be \'To Be Searched\' or \'Presentation\' or \'Search');
                flag = false;
            }
            if( oppNew.Destination_Zone__c == '')
            {
                oppNew.Destination_Zone__c.addError('Destination Zone is required');
                flag = false;
            }
            if(oppNew.Sold__c < 0)
            {
                oppNew.Sold__c.addError('Sold is required');
                flag = false;
            }
           
            if(flag)
            {
                oppNew.StageName = 'Ticketing';
                listOpp.add(oppNew);
                if (listOpp != null && !listOpp .isEmpty())
                {
                   Database.update(listOpp);
                }
                message ='Saved Successfully';
        }
        catch(System.CalloutException e)
        {
            message = e.getMessage();
        }
        return message;
    }
}

 

And call for custom button is

 

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

var oppId= "{!Opportunity.Id}";
var result = sforce.apex.execute("SubmitOrder","Submit",{oppId:oppId });

 

but getting following error

 

SObject row does not allow errors

 

Any help would be appreciated

Thanks in advance


Hi

 

I have two objects here

 

1)Transactions

2)Achieved

 

I have a field on Transactions named Amount

and a field on Achieved name Total Value

 

If a user does 7 transactions in a financial year , I want the total of the 7 transaction object  Amount field to add up to the Total Value field on Achieved object.

 

If the user deletes the transaction, the Total value field should be deducted also.

 

Financial year is 1 Jan 2012 - 31 DEC 2012. The transaction should be decided based on the created date.

 

Please help me on this

 

Thanks

HI All 

 

i need to create Edit button on my visual force page.In my custom visual force page there are three section. But i need to create Edit custom button on Every section and if i click that Edit button i want to Edit only that section 

 

can you please do some help!

 

 

 want to update another object say  1."account_master__c" from  2nd"ATM_transacction__c".writing after insert trigger in 2nd object.please look at the code.

 

trigger atm2 on ATM_Transaction__c (after insert)

{

for(atm_transaction__c atm: trigger.new)
{
aggregateResult a=[select sum(amount__c) s from atm_transaction__c where
account_id__c=:atm.account_id__c];

double i=(double)a.get('s');

account_master__c am=new account_master__c();
am=[select id, balance__c from account_master__c where
account_idm__c=:atm.accout_id__c]

if(am.balance__c > i){
am.balance__c=am.balance__c -i;
}
//update am;
}
update am;

}

 

where i wenr wrong.

thanks in advance.


Hi,

 

I have 2 output panels in  a VF page. 

 

Panel 1:

<apex:outputpanel><apex:pageBlock><apex:pageBlockTable>Some required fields<apex:pageBlockTable><apex:pageBlock> </apex:outputpanel>

 

Panel2:

<apex:outputpanel><apex:pageBlock><apex:pageBlockTable>A pageblocktable containing list of attributes<apex:pageBlockTable><apex:pageBlock></apex:outputpanel>

 

On click of Add/Remove for the pageBlockTable in Panel2, a controller method is invoked. A check for the required fields in Panel1 is being made and is getting re-rendered; and if  found null error messages are getting thrown.

 

I want to avoid the required field check for the Add/Remove click for Panel2.

 

In a nutshell, it wil be helpful to find a way to avoid making a controller call for Add/Remove.

 

Thanks in advance.