• r naresh
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 1
    Replies
Hi ,
i am new to salesforce development .please give me the  code ....
Hi to all,
 i am new salsforce developer .i have written some code for delete the duplicate records based on what we enter the name if exist ,otherwise need to insert.

but im not getting the result please correct me! Thanks in advance

trigger duplicatecontactdelete on Contact (before delete) 
{
  list<id> ls=new list<id>();
    for(contact c:trigger.old)
    {
        ls.add(c.id);
    }
   list<contact> deletecontact =[select id,name from contact where name in:ls];
    if(deletecontact.size()>0)
    {
        delete deletecontact;
    }
}
 
im getting this error please give me the solutuion Thank i advance
------------------------------------------------------------------------------------------------------
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger samedata caused an unexpected exception, contact your administrator: samedata: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0 with id 0039000001KC02vAAD; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]: Trigger.samedata: line 22, column 1


trigger samedata on Account (before insert,after insert) 
{
    Account a1=new Account();
    if(trigger.isbefore&&trigger.isinsert)
    {
for(Account a:trigger.new)
{
    a.name='naresh';
    a.phone='9989099890';
    a.email__c='naresh@axa.com';
    a1=a;
}
    } 
    else if(trigger.isafter&&trigger.isinsert)
    {
       list<contact> lc= new list<contact>();
        for(contact c:[select account.name,phone,email from contact where account.id=:a1.id])
        {
            
            lc.add(c);
        }
     insert lc;
    }
}
>..i am trying to do this
There are 1000 Users using one Profile (XXX)
In that for 10 Users need to Remove update Access for 5 Different Objects
How to do.?
1st user can access all Objects except (A Object should have only Read Permission), 2nd User can Access all Object except (B Object should have only Read Permission), 3rd User can Access all Object except(C Object should have only Read Permission)……..10th user can Access all Object except (X Object should have only Read permission).
Employee working under 7 Managers.whatever entering in to record 4 manager shounld only see remaing should not see what is the way and
How to restrict permissinos for remaing managers
im getting error in vf if i use the compaign id as value of column .
apex cls
-----------------
public integer avg{get;set;}
  list<AggregateResult> lAGR{get;set;}
  public exampleongroupby()
  {
   lAGR=[select campaignid,AVG(amount) avg from Opportunity group by campaignid];
  }
   public list<opportunity> getResult() 
   {
      list<opportunity> opp=new list<opportunity>();
      for(AggregateResult agr:lAGR)
      {
        opportunity op=new opportunity(agr);
        opp.add(op);
      }
        return opp;
   }
   class opportunity
   {
   public integer avg{get;set;}
     public opportunity(AggregateResult agr)
     {
      
     }
   }
}
vf page
------------
<apex:page controller="exampleongroupby">
  <apex:form >
    <apex:pageblock title="Test For AVG,COUNT(),COUNT_DISTINCT,MAX,MIN,SUM">
       <apex:pageBlockTable value="{!Result}" var="aar">
        
         <apex:column value="{!aar.avg}"/>
       </apex:pageBlockTable>
    </apex:pageblock>
  </apex:form>
</apex:page>


thank u in advance
here parent is department and child is employee

vf page
-------------
<apex:page controller="depttoemp">
  <apex:form >
    <apex:pageblock title="dept to emp">
      <apex:pageBlockTable value="{!dept}" var="d">
        <apex:column value="{!d.id}"/>
        <apex:column value="{!d.name}"/>
      </apex:pageBlockTable>
    </apex:pageblock>
  </apex:form>
</apex:page>

controller
--------------
public with sharing class depttoemp {
public list<Department__c> dept{get;set;}
public list<Employee__c> emp{get;set;}
public depttoemp ()
{
string soql='select id,name,(select id,name from Employee__r)from Department__c';
dept=Database.Query(soql);
}
}
im getting this problem
====================
System.QueryException: Didn't understand relationship 'Employee__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.










im getting this error please give me the solutuion Thank i advance
------------------------------------------------------------------------------------------------------
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger samedata caused an unexpected exception, contact your administrator: samedata: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0 with id 0039000001KC02vAAD; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]: Trigger.samedata: line 22, column 1


trigger samedata on Account (before insert,after insert) 
{
    Account a1=new Account();
    if(trigger.isbefore&&trigger.isinsert)
    {
for(Account a:trigger.new)
{
    a.name='naresh';
    a.phone='9989099890';
    a.email__c='naresh@axa.com';
    a1=a;
}
    } 
    else if(trigger.isafter&&trigger.isinsert)
    {
       list<contact> lc= new list<contact>();
        for(contact c:[select account.name,phone,email from contact where account.id=:a1.id])
        {
            
            lc.add(c);
        }
     insert lc;
    }
}