• Vi$h
  • NEWBIE
  • 75 Points
  • Member since 2014

  • Chatter
    Feed
  • 2
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 41
    Replies
Hi All, I trying to write my first trigger, failing hard. I would really appreciate any help.  Thank you, Matt

My Scenario: 
I have a custom object named Commerciant Customer Record that has a lookup field for Accounts. Every Account only has 1 Commerciant Customer Record that is imported into Salesforce. I have a lookup field on my Account object named Syspro Customer Record that needs to be passed the Id of the Commerciant Customer Record so I can link the two and write field formulas. Below are my field names and my trigger, I do not get any errors when saving it. Is my logic off and why does nothing happen when I create a new Commerciant Customer Record and link it to an account. 

Account = my parent object
Commerciant Customer Record (CommercientSF__ArCustomer__c) = child object
CommercientSF__AccountID__c = Lookup(Account) on Commerciant Customer Record Object
Syspro_Customer_Record__c = Lookup(Commerciant Customer Record) on Account object (the field I am trying up update)

trigger CustomerID on Account(after insert) {
if(trigger.isInsert)
  {
    set<Id> custId = new set<ID>();
    for(Account a : Trigger.New)
    {
       custID.add(a.Syspro_Customer_Record__c);
    }
    Map<Id, Id> custToAccountMap = new Map<Id, Id>();
    for(CommercientSF__ArCustomer__c c :[select Id, CommercientSF__AccountID__c from CommercientSF__ArCustomer__c where id in: custID])
    {
       custToAccountMap.put(c.id,c.CommercientSF__AccountID__c);
    }
    for(Account a: trigger.new)
    {
       a.Syspro_Customer_Record__c = custToAccountMap.get(a.Syspro_Customer_Record__c);
    }
   }
}


Hi

  Trying to write a trigger for my sobject. If record created time is more than 2 minitus for modified date and time it should not allow to edit.
already i have returned a trigger code,it's not working properly and try to change the existing code it getting error . please some budy help to resolve the issue. The code is below

 trigger Hourschange on transaction__c (before update) {
for(transaction__c s :Trigger.new){
double tm;
tm=((  System.now()-  s.CreatedDate.getTime() ) *1440);
//tm=double.ValueOf(system.NOW()- s.CreatedDate.GetTime())/365;

system.debug('hi::::::::::::::'+DateTime.now());
system.debug('hi::::::::::::::'+s.LastModifiedDate );
system.debug('hi::::::::::::::'+s.CreatedDate ); 

system.debug('hi::::::::::::::'+tm);

if(tm<=1){
system.debug('hi::::::::::::::'+tm);
s.payment_discription__c=' hi';
}
else
{
system.debug('bye::::::::::::::');
s.adderror('Alredy more than 60 minitus');
}
}
}


Before i worked the codition is  
double tm;
 tm= Math.Floor(integer.valueOf( s.LastModifiedDate.getTime()  -  s.CreatedDate.getTime() ) *1440);

There is a requirement to search fields in a look up.For this enhanced lookups need to be enabled, I have done this.There are some limitations with salesforce search. Relationship fields cannot be searched. One of our formula field gets value from other object and its not searchable, I want to be able to search on this field. I created a text field and used a workflow to populate it with the value from the master object.
Any change in the master object would not trigger the workflows. Other than writing a trigger on the master object is there any other option ?
  • February 13, 2015
  • Like
  • 0
I want to know whether we can publish Knowledge articles on site.com
I know that we can do it with force.com sites.
If we can do it on site.com, How do we do it ?
Any help is appreciated.
Thanks
  • July 01, 2014
  • Like
  • 1
When I click on a tab  I can see the recently view records but if I select 'All open leads' and click on go the page just keeps on loading.
This is happening in my developer org.
  • June 10, 2014
  • Like
  • 0
I want to know whether we can publish Knowledge articles on site.com
I know that we can do it with force.com sites.
If we can do it on site.com, How do we do it ?
Any help is appreciated.
Thanks
  • July 01, 2014
  • Like
  • 1
hi i have requirement where i have to built visual force page.. my data will be stored in db like followingUser-added image



i want to show my visual force like following

User-added image



i have written some sample code  to dispaly header..
 
public list<String> getagrmnts(){
        m.put('Name','');
        m.put('Driver__c','');
        period.add('Agreement no');
        period.add('Driver');
        headerKeys.add('name');
        headerKeys.add('driver__c');
        list<String> tempStr = new list<String>{};
        for(Agreement1__c a : al){
            flag = 1;
            tempStr.add(a.name);
            tempStr.add(a.driver__c);
            //if(period.indexOf(a.period__c)==-1)
            for(String p: period ){
                if(p == a.period__c){
                    flag = 0;
                }
            }
            if(flag == 1){
                m.put(a.period__c,'');
                headerKeys.add(a.period__c);
                period.add(a.period__c);
            }    
        }
        return period;    
    }

and page code to display header is
<apex:page controller="header">
<apex:pageBlock >
<table>
<tr>
<apex:repeat value="{!agrmnts}" var="c">
<td>
<apex:outputText value="{!c}"></apex:outputText>
</td>
</apex:repeat>
</table>
</apex:page>

please tell me how can i fill data to that table i want to mshow like above
Hi, has anyone faced similar issue like mine before? What happened is that a few days ago I tried to deploy something new from sandbox... and it failed because a few classes in the production failed its test....but the things I have had these classes in production for at least 2 years...and I even succesfully deployed something on the 20th of april 2015....and now those classes failed all of a sudden...the weird thing is I have the same classes in sandbox (obviously) and they pass the tests fine....so I yeah I am just baffaled as to why would something like this happen...why is it happening...
Please help me out, I can not identify which line will be executing throgh my test class,
It says 139 / 509 covered , But after double click the text execution it was navigating to the respective apex class. I can not see any blue/red line over there. Need any set up to get  that indicator.

Thanks in Advance!
 
i have a requirement to notify few folks on completion of the apex jobs. any suggestions around this

thanks in advance for your help

Hello,

I am trying to figure out if I need a trigger to update a field on the Account object when a field on the Contract object changes. 

For example, 

When Contract field, Status = "Activated", change Account field, Type to "Customer"

There is a relationship beteen the account and contract objects.

Thanks!


Shannon

Hi, I am new to salesforce and i have some question how do we acheive this in salesforce.

Let's say you are on Account detail page its Account name is xyz and i want to add Contact in its related list then i click new from Account detail page it redirects me to Contact detail page now when i add and save it, it redirect me to Contact detail page. But i want when i save Contact it should be added in the Account detail page and the Account detail page should come not Contact detail page.

Please help me how do i acheive this. please follow this link what i would like to say: http://quickst.ps/sf
There is a requirement to search fields in a look up.For this enhanced lookups need to be enabled, I have done this.There are some limitations with salesforce search. Relationship fields cannot be searched. One of our formula field gets value from other object and its not searchable, I want to be able to search on this field. I created a text field and used a workflow to populate it with the value from the master object.
Any change in the master object would not trigger the workflows. Other than writing a trigger on the master object is there any other option ?
  • February 13, 2015
  • Like
  • 0
I want to know whether we can publish Knowledge articles on site.com
I know that we can do it with force.com sites.
If we can do it on site.com, How do we do it ?
Any help is appreciated.
Thanks
  • July 01, 2014
  • Like
  • 1
Hi,

I am having a trigger on a custom object which creates a new lead record maps  the values of certian fields from custom to standard object,

In my custom object i have a field called as "Status" which is set to "qualified" and changes to "Unqualified" based on workflow written backend


Now my trigger is (after insert and after update) , when the lead status is qualified it creates only 1 lead record since there is no workflow or update 

but if the lead status is unqualified it creates 2 lead records , since there is an update at the backend,

How do i handle it in my trigger

This is my trigger


Trigger Leadprocess on Lead_Object__c(after insert , after update)
{
     List<Lead> sub=new List<Lead>();
     for(Lead_Object__c v : Trigger.new)
     {
         
                   Lead  s = new Lead();
                  // s.RecordType.name =v.Record_Type__c;
                   s.FirstName=v.First_Name__c; 
                   s.LastName =v.Last_Name__c;
                   s.Account_Type__c = v.Account_Type__c;
                   s.Units_In_Inventory__c = v.Units_In_Inventory__c;
                   s.Company = v.company__c;
                   s.PostalCode = v.Billing_Zip__c; 
                   s.AnnualRevenue =v.Annual__c;
                   s.Salutation  = v.Salutation__c;
                   s.LeadSource =v.Record_Type__c;
                   s.Status =v.Leadstatus__c;
                   s.Additional_Information__c =('The entered value of ZID is'+(v.ZID__c));  
                   sub.add(s);
           
           
            insert sub;
     }
}


Thanks in Advance
I am writing a wrapper class to to show atmost 100 elements of list using offset:

class Pg{
    public Integer displayLimit{get;set;}
    public Integer displayOffset{get;set;}
    public Boolean disableNext{get;set;}
    public Boolean disablePrev{get;set;}
    List collection;
   
    public Pg(){}
    public Pg(List collection){
        this.collection=collection;
        this.displayOffset=0;
        this.displayLimit=100;
        this.disablePrev=true;
        if (this.collection.size()>displayLimit) {
            this.disableNext=false;
        } else {
            this.disableNext=true;
        }
    }
   
    public void next(){
        this.displayOffset=this.displayOffset+displayLimit;
        if (this.collection.size()<displayOffset+displayLimit) {
            this.disableNext=true;
        }
        this.disablePrev=false;
    }

    public void prev(){
        this.displayOffset=this.displayOffset-displayLimit;
        if (this.displayOffset==0) {
            this.disablePrev=true;
        }
        this.disableNext=false;
    }
   
}

But here it is not allowing me to give List collection;
It needs something like List<Object> collection. Expecting Angle bracket after List.

But I want that I should able to pass List of any collection in constructor.

How to achieve this?
The code coverage of my Production instance dropped below 75% which has disabled the ability to move anything from Sandbox to production.
A developer - now no longer with company - helped improve in sandbox the test classes that needed to be fixed
I'd like to deploy the test classes to production, but when I try to do it via a change set I get the dreaded low coverage error (specifically "Average test coverage across all Apex Classes and Triggers is 68%, at least 75% test coverage is required")

It seems like a catch 22 -- I can't deploy the fix for the code coverage, since I don't have code coverage. :-( Any ideas?