• Vishal Kashyap
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies
the following Apex code shows how an account and a contact can be associated with one another, and then how the contact can be used to modify a field on the account: Account a = new Account(Name = 'Acme'); insert a; // Inserting the record automatically assigns a // value to its ID field Contact c = new Contact(LastName = 'Weissman'); c.AccountId = a.Id; // The new contact now points at the new account insert c; // A SOQL query accesses data for the inserted contact, // including a populated c.account field c = [SELECT Account.Name FROM Contact WHERE Id = :c.Id]; // Now fields in both records can be changed through the contact c.Account.Name = 'salesforce.com'; c.LastName = 'Roth'; // To update the database, the two types of records must be // updated separately update c; // This only changes the contact's last name update c.Account; // This updates the account name The question is how to implement this code.i am trying to implement this in trigger class but iam not able to do so.tell me where to write this code and how to execute.

Following are my set function a  

 

public with sharing class Mailer
{
public List<Acccon> ACCC{set;get;}
    public Mailer(ApexPages.StandardController controller) {
getACCC();
    }

    public class Acccon
    {
        public Boolean B{get;set;}
        public Contact C{get;set;}
        public Lead A{get;set;}
       
        public Acccon(Contact c,Lead A)
        {
           this.C=C;
           this.A=A;
           B=true;
        }
        public void setSearchText (Boolean Text)
        {
            B=Text;
        }
       
    }
    public void setB (Boolean Text)
    {
        for(Integer i=0;i<ACCC.size();i++)
        {
            ACCC[i].B=Text;
        }
   
    }
   
   
    public List<Acccon> getACCC()
    {
    system.debug('PPPPPPPPPPPPPPP');

 
  ACCC=new List<Acccon>();
   Contact[]  c= [select Id, firstName, Email, Phone from Contact limit 10];
   Lead[]  a= [select Description from Lead limit 10];
      system.debug(a.size()+'@@@@@@@@@@@@@@'+c.size());
        for(Integer i=0; i<10;i++)
        {
 system.debug(c[i]+'EEEEEEEE'+a[i]);
               ACCC.add(new Acccon(c[i],a[i]));
       }
    
        return ACCC;
    }

}

 

<apex:page standardcontroller="Contact" extensions="Mailer">
<apex:pageBlock >
<apex:pageblocktable value="{!ACCC}" var="A">
<apex:column ><apex:form >
<apex:inputCheckbox value="{!A.B}"/>
</apex:form></apex:column>
<apex:column value="{!A.A.Description}"/>

<apex:column value="{!A.C.email}"/>
</apex:pageblocktable>
<apex:form >
<apex:commandButton value="Mail Account Name(s)" action="{!sendmail}"/>
</apex:form>
</apex:pageBlock>

</apex:page>

After writing this trigger when I create an acount I get the error message 

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger CountAcc caused an unexpected exception, contact your administrator: CountAcc: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.CountAcc: line 9, column 1

 

Also can anybody please tell me how to do the update operation outside for loop?

 

 

trigger CountAcc on Contact (after insert){
    List<contact> NCL = trigger.new; 
    String AccountName;
        
    for(Contact C:NCL)
    {
        AccountName=C.AccountID;
        Account A=new Account();
        A=[Select noc__C from Account where ID=:AccountName];
        A.noc__C++;
        Database.update(A);
     }
}

 

apex code:-

 

public with sharing class Mailer
{
public class Acccon
{
Boolean B=true;
Contact C{get;set;}
Account A{get;set;}

public Acccon(Contact Cpas)
{
C=Cpas;
}
public Acccon(Account Apas)
{
A=Apas;
}
}

public List<Acccon> ACCC{set;get;}
public List<Acccon> getACCC()
{
for(Contact c: [select Id, firstName, Email, Phone from Contact limit 10])
{

ACCC.add(new Acccon(c));
}
for(Account a: [select Name from Account limit 10])
{

ACCC.add(new Acccon(a));
}
return ACCC;
}
}

 

VF page code:-

<apex:page controller="Mailer">
<apex:pageBlock >
<apex:dataTable value="{!ACCC}" var="a">
<apex:column value="{!a.A.name}"/>

</apex:dataTable>
</apex:pageBlock>
</apex:page>

once we create anyuser we can only disable him?

 

But is there any way to delete this user using either eclipse / some other way?

Hi All, I am trying to integrate SFDC with TIBCO by exposing webservice from SFDC side . When Tibco make a callout by using the SFDC login() core call they are hitting a exception : CA certificate with issuer ou=Class 3 Public Primary Certification Authority,o=VeriSign, Inc.,c=US and serial number 1B09 3B78 6096 DA37 BBA4 5194 46C8 9678 is not a trusted certificate Sending alert: Alert Fatal: bad certificate: TIBCO is asking for certificates from SFDC side As far as i know SFDC OOB doesn't provide any certificate and we don't need certificates to make a call out to SFDC . Please provide inputs for this error

What will happen to validation rules and mandatory fields of an object when inserting records through apex class but not following validation rules or not providing the mandatory field values.

 

consider account object has name, city (mandatory), max_salary(has some validation rule), phone number fields.

 

if i insert

account s = new account (name =' bob', phone = '7896785678', max_salary='50000');

 

what will happen to this line while executing, will it fail because i have not provided mandatory field (city) and didn't follow validation rule for max_salary field. 

I'm trying to pull the Managers NAME (not ID) of the opportunity owner and display it on the opportunity record.  I was able to do this by copying the below trigger someone else had posted.  It works great but I want the manager "time stamped" meaning, I don't want the managers name to be updated if it happens to change.  I only want the field to display the manager of the opp owner at the time the opp was created. 

 

How can I do this??

********************************************************

 

trigger UpdateOwnerManager on Opportunity (before insert, before update ){
  /**
  1. For each opportunity being inserted add User Id value in in Set of User Ids.
  2. Fetch all Users whose Id is in the Set.
  3. Add these fetched Users in a Map <User Id, User object>
  4. for each opportunity being inserted get User from the map and update the field values  
  **/  
 
  //holds User Ids
  Set<Id> setUserIds = new Set<Id>();
 
  //holds a list of Users
  List<User> lstUser = new List<User>();
 
  //holds key value pairs of User Id and User Object
  Map<Id, User> mapUserObj = new Map<Id, User>();

  //holds User object
  User UserObj;
   
  //For each opportunity being inserted add User Id value in in Set of User Ids.
  for(Opportunity oppObj : Trigger.new){
    if(oppObj.OwnerId != null){
      setUserIds.add(oppObj.OwnerId);
    }
  }
 
  //Fetch all Users whose Id is in the Set.
  lstUser = [select Id, Name, ManagerId from User where Id in :setUserIds Limit 1000];
  if(lstUser.size() == 0){
    return;  
  }
 
  //Add these fetched Users in a Map <User Id, User object>
  for(User usrObj : lstUser){
    mapUserObj.put(usrObj.Id, usrObj);  
  }
 
  //for each opportunity being inserted get User from the map and update the field values
  for(Opportunity oppObj : Trigger.new){
    //get User object
    if(oppObj.OwnerId != null){
      if(mapUserObj.containsKey(oppObj.OwnerId)){
        UserObj = mapUserObj.get(oppObj.OwnerId);
        //map opportunity fields to User fields
        oppObj.Opportunity_Owner_s_Manager__c = UserObj.ManagerId;
      }  
    }
  }
}

 

the following Apex code shows how an account and a contact can be associated with one another, and then how the contact can be used to modify a field on the account: Account a = new Account(Name = 'Acme'); insert a; // Inserting the record automatically assigns a // value to its ID field Contact c = new Contact(LastName = 'Weissman'); c.AccountId = a.Id; // The new contact now points at the new account insert c; // A SOQL query accesses data for the inserted contact, // including a populated c.account field c = [SELECT Account.Name FROM Contact WHERE Id = :c.Id]; // Now fields in both records can be changed through the contact c.Account.Name = 'salesforce.com'; c.LastName = 'Roth'; // To update the database, the two types of records must be // updated separately update c; // This only changes the contact's last name update c.Account; // This updates the account name The question is how to implement this code.i am trying to implement this in trigger class but iam not able to do so.tell me where to write this code and how to execute.