• cvuyyuru
  • NEWBIE
  • 335 Points
  • Member since 2011
  • Salesforce Architect


  • Chatter
    Feed
  • 10
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 77
    Replies
We are currently introducing Salesforce (Sales Cloud & Service Cloud) to support our custom CRM system. Therefore, we are looking for senior Salesforce experts with experience in integrating Salesforce in existing infrastructures (REST) with a two-way data synchronization.

Your tasks
  • You are responsible for managing Salesforce in a team and acting as a contact for all technical issues
  • You coordinate customizations and extensions in Salesforce and implement them independently It supports the connection of Salesforce to internal and external systems
  • With your expertise, you can ensure the data quality and integrity of Salesforce data

You bring that with you
  • You have a university degree in computer science or similar or several years of experience in salesforce development
  • You are motivated to work with different departments and to understand their challenges
  • You radiate a confident demeanor and keep a cool head even in heated discussions
  • You have in-depth knowledge of the SalesCloud environment and, ideally, know-how in the ServiceCloud or MarketingCloud

https://caronsale.de/career/
Hi

I have an apex trigger that takes a contact from the contact roles on opportunity, and adds it to a look up field on the opportunity called opportunity_contact__c.

I also need this to then go to another lookup field on the oportunity line items, also called opportunity_contact__c. Can anyone help me with this? Trigger below:
 
trigger MnCopyPrimaryContact on Opportunity (before update) {
    Set<Id> setOfIds = new Set<Id>();
    for (Opportunity o : Trigger.new) {
        if(o.Id!=Null){
            setOfIds.add(o.Id);
        }
    }
    OpportunityContactRole[] contactRoleArray= [select ContactID, isPrimary from OpportunityContactRole where OpportunityId IN :setOfIds  order by isPrimary desc,CreatedDate];
    for (Opportunity o : Trigger.new) {
        if (contactRoleArray.size() > 0) {
            o.Opportunity_contact__c = contactRoleArray[0].ContactID;           
        }else{
            o.Opportunity_contact__c = null;
        }
    }
}

Many Thanks
Conor​
Im always having problems with the "Programme Area" object. It never seems to want to test and Its always at this point I get stuck.
User-added imageUser-added imageUser-added image
Can somone help me with what im missing and tell me how you knew what I needed and where I needed it thankyou.
If it helps the "Programme Area" is a master Detail.

Thanks Dan
Here is my Test class

@isTest
public class accountExplorer_Test {

    private static testMethod void test() {
       
        accountExplorer hadlerObj = new accountExplorer();
        hadlerObj.accountCollect();
        Transaction__c tansObj = new Transaction__c();
        tansObj=accountExplorer.transDeatils();
        accountExplorer.transNameHandler();
    }    
}

Here is Apex Class:
public class accountExplorer {
   public accountExplorer(){
        system.debug('Inside Constructor');
    }
    //Non Static method : Variable declaration
    List<Account> accountCollectVar = new List<Account>();
    
    //Non-Static method declaration and its body : Account details displayer
    public Account accountCollect(){
        accountCollectVar = [SELECT ID, Name, AccountNumber FROM Account WHERE name='addepalli' OR name='katru'];
        system.debug('Account Details in non-statis method:' +accountCollectVar);
        return accountCollectVar[1];
     }
    //Static Method : Variables declaration Note: Static method not allowing variables to be declared inside methoid body??  ?
    Static Set<Transaction__c> transDetailsVar = new Set<Transaction__c>();
    Static List<Transaction__c> transDetailsVarList = new List<Transaction__c>();
    
    //Metho declaration with method body : Displays all transaction names and its type
    public static Transaction__c transDeatils(){
        transDetailsVarList = [SELECT Name, TransactionType__c FROM Transaction__c WHERE TransactionType__c = 'deposit'];
        transDetailsVar.addAll(transDetailsVarList);
        system.debug('Transaction details:'+transDetailsVar);
        return transDetailsVarList[1];
       
    } 
   
   // Static method, with string return type : Display transaction Name
   //Static string transName{get;set;}
    public static string transNameHandler(){
            Transaction__c transObject = new Transaction__c();
            transObject = [SELECT Name from Transaction__c WHERE TransactionType__c = 'deposit' LIMIT 1];
            system.debug('Transaction name :' +transObject.name);
            return transObject.name;
        }
}
 
Here is my Code 
trigger OppAmount on Opportunity (after insert,after update,after delete,after undelete) {
if(Trigger.isInsert || Trigger.isUpdate  || trigger.isUndelete)
{
set<Id> OppId=new Set<Id>();
for(opportunity o:Trigger.new)
{
OppId.add(o.accountid);
}
Decimal i=0;
List<Opportunity> ls=[select amount from opportunity where accountid in:OppId];
List<Account> l=[select id from account where id in:OppId];
List<account> l1=new List<Account>();


for(Opportunity o:ls)
{
if(o.Amount !=null)
{
i=i+(o.Amount);
}
}
for(Account a:l)
{
a.Opportunity_Amount__c=i;
l1.add(a);
}
update l1;
}

if(Trigger.isDelete )
{
Set<Id> accid=new Set<Id>();
for(Opportunity o:Trigger.old)
{
accid.add(o.accountid);
}
List<Account> ls=[select id,Opportunity_Amount__c,(select accountid,amount from opportunities) from account where id in:accid];
list<account> ls2=new list<account>();
decimal i7;
for(Account a:ls)
{

for(opportunity o:a.opportunities)
{

i7= a.Opportunity_Amount__c - (o.Amount);
a.Opportunity_Amount__c=i7;
}

ls2.add(a);
}
update ls2;
}
}

Its Working for insert and Update,but when i delete a particular Opportunity the amount field on trigger is not updating the subtracted value instead it is updating the deleted opportunity amount value
I upload a image and use google vision api ocr it:
public blob file { get; set; }

public void uploadImage()
    {
String b64String = EncodingUtil.base64Encode(file);		
            Http http = new Http();	 
            HttpRequest  request = new HttpRequest();
            request.setMethod('POST');	     
            request.setHeader('Content-Length', '2000');
            request.setHeader('Content-Type', 'application/json');             
            request.setEndpoint('https://vision.googleapis.com/v1/images:annotate?key=AIzaSyDY2VbfNW9rIXOJs9O....');	        
                 
            request.setBody(b64String);	        
            HttpResponse response = http.send(request);	        
            imagetext= response.getBody();
           System.debug(imagetext);
}

Result:
00:01:19.61 (1062397547)|USER_DEBUG|[82]|DEBUG|{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Expected a value.\n/9j/4AAQSkZJRgABAQAA\n^",
    "status": "INVALID_ARGUMENT"
  }
}
How can call google vision api from apex?
Thank you.
 
Hi All,
        my need is that when a child case is created for compliance team to handle,  no notification is received by the compliance team. the tem should receive the notification?
Any suggestion?
hi,

i have a test class.It is throwing error System.Assertexception
Lead newLead = new Lead();
        newLead.LastName='TestName';
        newLead.Company = 'TestCompany';
        newLead.Email='test@test.com';
        newLead.Status ='Open';
        newLead.Cc__c='test@test.com';
        newLead.Description='Subject:TextBody';
        insert newlead;
          
      Messaging.InboundEmail email = new Messaging.InboundEmail() ;
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

        email.plainTextBody = 'teset';
        email.fromAddress = 'test@test.com';
        email.subject = 'Test Lead';
       // email.ToAddress ='test@gmail.com';
        CreateLeadExample  edr = new CreateLeadExample();
        edr.handleInboundEmail(email,env); 

        Test.startTest();
        Messaging.InboundEmailResult result = edr.handleInboundEmail(email, env);
         System.assert(result.success, 'Error processing email...');
        Test.stopTest();
               
        Lead [] leadDb = [SELECT Id FROM Lead where LastName=:email.FromAddress];
       // System.assertEquals (1, leadDb.size(),'Lead was not inserted');
       System.debug('Size'+leadDb.size());
       
        attachment.body = blob.valueOf('my attachment text');
        attachment.fileName = 'text';
        email.binaryAttachments =
        new Messaging.inboundEmail.BinaryAttachment[] { attachment };
        Attachment attach=new Attachment();     
        attach.Name='Test';
        Blob bodyBlob=Blob.valueOf('Testing Body of Attachment');
        attach.body=bodyBlob;
        insert attach;

the result.success is getting false.how can i resolve this error

thanks
I have successfully wrote a trigger which calculates all the newly completed activities (Email & Call) and update the total number of a custom filed on the lead object. Similary, I would like to do the same for the completed task which are already completed before the trigger was written however unable to get what the code should be. Below is the trigger that I wrote for the calulcated the New Task :

trigger NoOfEmail on task (after insert, after update) {
    id leadid;
    integer inr = 0;
    List <task> leadTask = new List <task>();
    if (trigger.new!= null) {
        for (task t : Trigger.new) {
            leadid = t.WhoId;
        }
    }
    leadTask = [select id, subject, Status from task where whoid=:leadid];
    for(task t : leadTask){
        if ((t.Subject == 'Email' || t.Subject == 'Call') && t.Status == 'Completed'){
            inr = inr+1;
        }
    }
    
    List <lead> led1 = new list <lead> ();
    List <Lead> led = [select id from lead where id = :leadid];
    for (lead l : led){
        led1.add(l);
        l.Number_of_Activity__c = inr;
    }    
    
    if(led1.size()>0){
        update led1;
    }
}
@RestResource(urlMapping='/PortalUser/*')
Global Class rolesException extends Exception {
    @HttpPost   
    global static String CreateNewUser()  
        {             
     
         RestRequest req = RestContext.request;    
         System.debug('RestRequest___: '+ req);     
         RestResponse res = RestContext.response;   
         System.debug('RestResponse___: '+ res);    
         Blob b = req.Requestbody;                 
         Wrapperclss reg = rolesException.parse(b.tostring());
            Savepoint sp = Database.setSavepoint();

         Try{    
               if(reg.firstname==null || reg.firstname=='')
                {
                    throw new rolesException ('enter firstname');
                }
                if(reg.lastname==null || reg.lastname=='')
                {
                    throw new rolesException ('enter lastname');        
                }
                //if(Pattern.matches('[a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z]{2,4}',reg.Email))
                //{                        
                  //     throw new rolesException ('Please enter valid emailid');
                //} 
                
                 if(reg.role==null || reg.role=='')
                 {
                    throw new rolesException('role is required');  
                 }        
                 /*list<contact> sr =[SELECT  lastName, Role__c from Contact where  Role__c=:reg.Role];
                 system.debug('enter@@@'+sr);
                 if(sr.size()<=0)
                 {
                    throw new rolespostportalException('role is requiredee');        
                 }*/
                 
                 list<Role__c>role=[select Name,Type__c from Role__c where type__c =:reg.Role];
                 system.debug('Enter__'+role);
                 if(role[0].type__c == 'Manager')
               {
                   List<Contact> con = [SELECT Id, Name FROM Contact WHERE accountId=:reg.AccountID AND Role__c=:role[0].Id];
                   if(con.size()>0)

                   {
                       throw new rolesException('Manager already exist');
                   }
               }
               if(reg.username!=null || reg.username!='')

                   {

                    List<User> u = [SELECT username FROM User WHERE username =:reg.username];

                    if(u.size()>0)

                   {

                       throw new rolesException('User already exist');
     }

                    }
            
            Contact C1 = new Contact( AccountID =reg.AccountID, firstName = reg.Firstname, lastName =reg.lastname ,email =reg.Email, role__c = role[0].id);
            insert C1;
                User newUser = new User();           
                newUser.Username =reg.username;     
                newUser.LastName = reg.lastname;
                newUser.Firstname = reg.Firstname;
                newUser.Email = reg.Email;      
                newUser.ContactId =C1.id ;
                newUser.Alias =reg.Alias;
                newUser.TimeZoneSidKey = reg.TimeZoneSidKey;
                newUser.LocaleSidKey = reg.LocaleSidKey;
                newUser.EmailEncodingKey = reg.EmailEncodingKey;
                newUser.LanguageLocaleKey = reg.LanguageLocaleKey;
                newUser.CommunityNickname= reg.CommunityNickname;
                newUser.ProfileId= reg.ProfileId;         
                insert newUser;        
                return 'User Created! Id Is: ' + newUser.Id; 
            }
               catch(Exception e)
               {
                    Database.rollback( sp );
                    system.debug('error____:enter valid ID'+e);
                    return e.getMessage();
               }
        }
               global static Wrapperclss parse(string reg) 
               {       
                   return(Wrapperclss)System.json.deserialize(reg,Wrapperclss.class);  
               }   
               global class Wrapperclss  
                {      
                    global String username{get;set;} 
                    global String Firstname{get;set;} 
                    global String LastName{get;set;}     
                    global String Email{get;set;}    
                    global String ContactId{get;set;}   
                    global String Role{get;set;}
                    global String Alias{get;set;}   
                    global String TimeZoneSidKey{get;set;}   
                    global String EmailEncodingKey{get;set;} 
                    global String LanguageLocaleKey{get;set;}
                    global String LocaleSidKey{get;set;}
                    global String CommunityNickname{get;set;}
                    global String ProfileId{get;set;}   
                    global String AccountID{get;set;}   

                }    
          
    }
// Create a list of contacts
List<Contact> conList = new List<Contact> {
        new Contact(FirstName='Joe',LastName='Smith',Department='Finance'),
        new Contact(FirstName='Kathy',LastName='Smith',Department='Technology'),
        new Contact(FirstName='Caroline',LastName='Roth',Department='Finance'),
        new Contact()};
            
// Bulk insert all contacts with one DML call
Database.SaveResult[] srList = Database.insert(conList, false);
// Iterate through each returned result
for (Database.SaveResult sr : srList) {
    if (sr.isSuccess()) {
        // Operation was successful, so get the ID of the record that was processed
        System.debug('Successfully inserted contact. Contact ID: ' + sr.getId());
    } else {
        // Operation failed, so get all errors
        for(Database.Error err : sr.getErrors()) {
            System.debug('The following error has occurred.');
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Contact fields that affected this error: ' + err.getFields());
	 }
    }
}
I am getting invalid constructor syntax error in anonymous apex. this code is from trailhead in which database method is used.